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!!
In my situations, the IUSR account needed permissions in the destination directory. Not the ISS_IUSR account, just the IUSR account.
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
andsafe_mode_exec_dir
and experiment with them.