【发布时间】:2014-05-07 11:17:57
【问题描述】:
我有一个要用来创建日志文件的 php 脚本。但它不会这样做,权限被拒绝。 从语法上讲,我认为我的代码对于编写文件是正确的,但我不知道如何(安全地) 允许 php 在目录中创建文件。
> [Wed May 07 07:01:28.827861 2014] [:error] [pid 2457] [client
> 10.0.0.123:63383] PHP Warning: fopen(Log filename: 1399460488.txt): failed to open stream: Permission denied in /home/j0h/www/test/iv.php on line 7, referer:
> http://10.0.0.123/test/
这是一个使用 php5.4 的 linux 服务器 这是我试图用来编写文件的代码: 第 7 行以 $handle 开头 ...
<?php
//Time... for some logs
$t=time();
//create Log filename based of Epoch
$LogName = $t . ".txt";
$handle = fopen($LogName, 'w') or die('Cannot open file: '.$LogName);
$file = fopen( $LogName, "w" );
if( $file == false )
{
echo ( "Error in opening new file" );
exit();
}
fwrite( $file, "This is a simple test\n" );
fclose( $file );
?>
【问题讨论】:
-
文件是只读的吗?
-
我想即时创建日志文件。它们还不存在。
-
您需要在属性中授予 iv.php 文件 777 权限 - 用于读写文件。 movabletype.org/documentation/assets/777.png
-
那么777权限呢?
标签: php linux file-io permissions