note 41197 added to function.chmod
| From: | agrenier at assertex dot com | Date: | Fri, 02 Apr 2004 10:11:09 +0000 |
| Subject: | note 41197 added to function.chmod | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-67512@lists.php.net to get a copy of this message | ||
This function will chmod a $filename before writing to it if:
1 - It exists
2 - It is not writeable
3 - PHP has permission to chmod files
If PHP can't chmod, then the script will end. Otherwise it will attempt to write to a new file.
<?php
function file_write($filename, $flag, &$content) {
if (file_exists($filename)) {
if (!is_writable($filename)) {
if (!chmod($filename, 0666)) {
echo "Cannot change the mode of file ($filename)";
exit;
};
}
}
if (!$fp = @fopen($filename, $flag)) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($fp, $content) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
if (!fclose($fp)) {
echo "Cannot close file ($filename)";
exit;
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.chmod.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41197
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41197&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41197&report=yes
Search -- http://master.php.net/manage/user-notes.php