【问题标题】:PHP File Editing problemsPHP文件编辑问题
【发布时间】:2013-01-31 00:12:33
【问题描述】:

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

【问题讨论】:

  • 你试过在文件名前加绝对路径吗?
  • 你是fopen("Ips.txt")file_get_contents("/User/WebServer/Desktop/Ips.txt") .. 是同一个文件吗?
  • 哎呀,忘了更新,是的,我尝试使用绝对路径。
  • 你真的应该使用绝对路径,除非你非常确定当前的工作目录是什么。
  • 修复了,更新了,没用

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-21
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多