PHP/IIIS copy()/move_uploaded_file()无法打开流:权限被拒绝警告


PHP/IIS copy()/move_uploaded_file() failed to open stream: Permission denied Warning

我对web开发相对陌生,目前遇到了一个无法解决的错误。

输入"http://localhost/index.html"并选择要上传的示例文件,它会生成以下警告:

Warning: move_uploaded_file(upload/Angela_Nie_resume_technical - EditedMW.doc): failed to open stream: Permission denied in C:'inetpub'wwwroot'test.php on line 26
Warning: move_uploaded_file(): Unable to move 'C:'Windows'Temp'php74F2.tmp' to 'upload/Angela_Nie_resume_technical - EditedMW.doc' in C:'inetpub'wwwroot'test.php on line 26

下面是与移动我的文件相关的代码。

$target_dir = "upload/"; 
$target_file = $target_dir . basename( $_FILES["uploaded"]["name"]) ; 
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target_file))  {
    echo "The file has been uploaded"; 
}  
else { 
    echo "Sorry, there was a problem uploading file."; 
}

我使用的是Windows 8.1,并使用IIS来运行localhost。提前谢谢你帮我!!

在我的情况下,IUSR帐户需要目标目录中的权限。不是ISS_IUSR帐户,只是IUSR帐户。

这意味着运行apache服务器的用户没有upload/目录的写入权限。您可以右键单击文件夹并设置对每个人的写入权限。

更新

这可能是因为您的PHP处于安全模式,并且不执行之类的命令,将一个文件移动到另一个。检查php.ini中的safe_modesafe_mode_exec_dir,并对它们进行实验。