所以这是我的代码:
<?php
$path = 'logs/' . date("Y:m:d") . '.txt';
$get = $_POST['data']; // I know this is insecure, don't worry
$file = fopen($path, 'w') or die("Something is wrong with your file permissions, please obtain the nessecary rights!");
fwrite($file, $get) or die('error writing to file');
?>
fopen()
功能正常,我不会得到任何错误。问题是我得到了一个&#34; error writing to file
&#34;意思是我的fwrite()
函数有问题。
这可能是什么问题?
我正在使用apache2和php7。
答案 0 :(得分:3)
由于文件名的名称,它不起作用,如:
$path = 'logs/' . date("Y:m:d") . '.txt';
正如您将注意到的,您生成的路径类似于: logs/2016:12:18.txt
,暗示 .txt
文件的名称是 2016:12:18
,它不是文件名的有效名称,不能包含冒号( :
)。
请注意;命名文件时,不能使用以下字符:
您应该修改为可接受的文件名,以使其正常工作。
下面是一个示例,使用连字符( -
)作为分隔符:
$path = 'logs/' . date("Y-m-d") . '.txt'; // Expected result: logs/2016-12-18.txt