0

嗨我想用php写一个文件,但我什么都写不出来。当我编写此测试函数时,出现“无法更改文件定名的模式”错误。如何使用 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); 
?>
4

3 回答 3

1

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

于 2011-04-25T05:52:11.770 回答
0

我想主要是“当前用户是运行 PHP 的用户”。您可以chmod对通过 php 脚本创建的文件执行吗?

于 2011-04-25T06:14:54.370 回答
0

我不确定你是否调查过 umask

于 2011-04-25T07:17:32.613 回答