note 38237 added to function.fwrite
| From: | Graham at rn2 dot php dot net | Date: | Sat, 13 Dec 2003 09:04:49 +0000 |
| Subject: | note 38237 added to function.fwrite | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61891@lists.php.net to get a copy of this message | ||
<?php
$filename = "example.txt";
if (!$handle = fopen($filename, 'a')) {
print "Cannot open file ($file)";
exit;
}
$somecontent = "Hello";
if(is_writable($file)){
if (!fwrite($handle, $somecontent)) {
print "Cannot write to file ($file)";
exit;
}
} else {
chmod ($file , 0777) or die ("I found out you couldn't write to the file so I tried to
chmod it but it didn't work");
echo "Please refresh the page";
}
?>
That example will write hello to example.txt if example.txt is writable, otherwise it will chmod and
ask the user to refresh so it can try again. I know the code is a bit tatty at being presented but I
am not very good at that.
----
Manual Page -- http://www.php.net/manual/en/function.fwrite.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38237
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38237&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38237&report=yes
Search -- http://master.php.net/manage/user-notes.php