chmod is not working on php and I can not write a file!
Hi I want to write in a file with php, but I can not write anything. When I write this test function I got "Cannot change the mode of file deneme" error. How can use chmod and so that I can write into a file thanks for helping..
<?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;
}
}
$a="osman"; file_write("deneme", "w", &$a);
?>开发者_如何学运维;
Refer to php manual and chmod() function http://php.net/manual/en/function.chmod.php as you need write permissions for that folder/file
I guess tha main thing is "The current user is the user under which PHP runs." Can you perform chmod
on the file you've created via php script?
I am not sure if you looked into umask.
精彩评论