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

和自甴很熟 提交于 2019-12-12 09:44:02

问题


I am relatively new to web development and currently ran into an error I can't solve.

I use IIS to test my php after typing in "http://localhost/index.html" and select the example file to upload, it generates the following warnings:

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

Below is the code that is related with moving my files.

$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."; 
}

I am using Windows 8.1 and using IIS to run localhost. Thank you in advance for helping me out!!


回答1:


That means that user who is running the apache server does't have write permissions for upload/ directory. You can right click the folder and set permission for writing to everyone.

Update

It might be because your PHP is in safe mode and doesn't execute commands like move one file to another. Check your php.ini for safe_mode and safe_mode_exec_dir and experiment with them.




回答2:


In my situations, the IUSR account needed permissions in the destination directory. Not the ISS_IUSR account, just the IUSR account.



来源:https://stackoverflow.com/questions/29127789/php-iis-copy-move-uploaded-file-failed-to-open-stream-permission-denied-war

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!