chmod没有在php上工作,我无法写一个文件!

时间:2011-04-25 05:50:11

标签: php chmod fwrite

您好我想用php编写一个文件,但我不能写任何东西。当我写这个测试函数时,我得到了“无法更改文件deneme的模式”错误。如何使用chmod,以便我可以写入文件,感谢您的帮助..

   <?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); 
?>

3 个答案:

答案 0 :(得分:1)

请参阅php手册和chmod()函数http://php.net/manual/en/function.chmod.php,因为您需要对该文件夹/文件的写入权限

答案 1 :(得分:0)

我想主要的是“当前用户是PHP运行的用户。”你能通过php脚本在你创建的文件上执行chmod吗?

答案 2 :(得分:0)

我不确定你是否考虑过umask

相关问题