我想用PHP制作一个datelog文件。我在macbook上的xampp上运行它。它一直表示许可被拒绝。我该如何解决?
我得到的错误是:警告:fopen(星期五 - 01 - 4月 - 16.txt):无法打开流:第6行/Applications/XAMPP/xamppfiles/htdocs/aowigman/index.php中的权限被拒绝无法打开文件!
代码:
<?php
date_default_timezone_set("Europe/Amsterdam");
$datum = date("l-d-F-y");
$ip = $_SERVER["REMOTE_ADDR"];
$myfile = fopen("$datum".".txt", "a+") or die("Unable to open file!");
$txt = $datum. " ". $ip."\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
提前致谢!
您可能需要以管理员身份更改权限。在Mac上打开终端,然后打开该文件所在的目录。然后键入:
sudo chmod 777 -R on directory file located
转到Xammp目录,右键单击并选择Read informations。在其底部,单击链,输入您的密码并更改读取和写入所有人的权限。现在,单击cog并选择Apply to included元素。
刷新包含代码的页面,tadam,fopen(),file_put_contents()等将起作用。