0

我最近一直在使用 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文件权限不合适。

4

1 回答 1

0

我想通了,原来 IPs.txt 不知何故失去了用户编辑的权限,我添加了权限,并解决了问题,感谢所有帮助!

于 2013-02-15T17:43:56.913 回答