-
writing to text file
i uploaded a text file called 'logs.txt' and write.php to a www folder on a server (i got a subdomain)
so the links to these are like, E.G:.
www.site-here.com/logs.txt
www.site-here.com/write.php
then why doesnt something like this work:
www.site-here.com/write.php?txt=Hello
and it should write the word 'Hello' to logs.txt
Heres write.php..
PHP Code:
<?php
$filename = 'logs.txt';
$somecontent = $_GET['txt'] . "\n";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>
any help guys?
i just keep getting: Cannot write to file logs.txt
-
Re: writing to text file
Turn on error handling by adding this to the top of your script. This should tell you what error, if any is causing the script to fail.
PHP Code:
error_reporting(E_ALL);
-
Re: writing to text file
Remember, I'm a n00b ;) but....
I think you need to make sure you give "logs.txt" write permissions to others.
I got an error with this permissions:
-rw-rw-r-- 1 user user 12 Sep 19 17:59 logs.txt
Works fine with this permissions:
-rw-rw-rw- 1 user user 12 Sep 19 17:59 logs.txt