|
-
Sep 19th, 2005, 02:56 PM
#1
Thread Starter
Frenzied Member
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
Last edited by Pouncer; Sep 19th, 2005 at 03:00 PM.
-
Sep 19th, 2005, 04:31 PM
#2
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);
-
Sep 19th, 2005, 05:02 PM
#3
New Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|