PHP文件编辑问题

时间:2013-02-15 02:47:09

标签: php iis file-io windows-7 webserver

我最近一直在使用IIS和PHP,但无法编辑文件。我允许将wwwroot文件编辑为IIS_IUSRS,但这似乎没有做任何事情。我仍然收到以下警告:

Thanks for your request, *My IP Here* The robot moved forward. Warning: fopen(Ips.txt): failed to open stream: Permission denied in C:\inetpub\wwwroot\CMD.php on line 20 Unable to open file, Ips.txtPermission denied in C:\inetpub\wwwroot\CMD.php on line 20 Unable to open file, Ips.txt

如果我理解正确,这意味着wwwroot不对php编辑开放。 这是我的代码:

<?php
$cmd=$_GET["cmd"];
$ip=$_SERVER['REMOTE_ADDR'];
if($cmd=="Forward") {
//insert forward code here.
    echo "Thanks for your request, ".$ip." The robot moved forward.";

} else if($cmd=="Backward") {
//insert backwards code here.
    echo "Thanks for your request, ".$ip." The robot moved backwards.";
} else if($cmd=="Left") {
//insert left code here.
    echo "Thanks for your request, ".$ip." The robot moved left.";
} else if($cmd=="Right") {
//insert right code here.
    echo "Thanks for your request, ".$ip." The robot moved right.";
} else {
    echo "Got invalid command: ".$cmd." From IP: ".$ip;
}
$ipfile = fopen("C:/inetpub/wwwroot/Ips.txt",'w') or exit("Unable to open file, Ips.txt");
if(!strpos(file_get_contents("C:/inetpub/wwwroot/Ips.txt"),$ip)) {
    fwrite($ipfile,$ip);
}
echo "\nYour IP has been logged for security purposes.";
fclose($ipfile);
$log=fopen("C:/inetpub/wwwroot/Logs.txt",'w') or exit("Unable to open file, Logs.txt");
fwrite($log,"Got command, ".$cmd." from a computer at the adress, ".$ip);
fclose($log);
?>

我已经浏览了很长一段时间,并且发现了类似的情况,但是找不到解决方案,或者关于不正确的IIS文件权限。

1 个答案:

答案 0 :(得分:0)

我明白了,事实证明IPs.txt在某种程度上失去了用户编辑的权限,我添加了权限,并修复了问题,感谢所有的帮助!