PHP 8.5.0 Alpha 4 available for testing

Voting

: six minus three?
(Example: nine)

The Note You're Voting On

agrenier at assertex dot com
21 years ago
This file_write() function will give $filename the write permission before writing $content to it.

Note that many servers do not allow file permissions to be changed by the PHP user.

<?php
function file_write($filename, &$content) {
if (!
is_writable($filename)) {
if (!
chmod($filename, 0666)) {
echo
"Cannot change the mode of file ($filename)";
exit;
};
}
if (!
$fp = @fopen($filename, "w")) {
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;
}
}
?>

<< Back to user notes page

To Top