3
votes

I have a PHP web application running on IIS, which allows a user to upload a file from a simple html form. The uploaded file is then moved to a folder on another server. This is working correctly on Apache, but fails on IIS with the error:

function['move_uploaded_file']failed to open stream: Permission denied in...

I've checked all the permissions on the directories. If I run a simple PHP script through the command line to copy a file from the server into the folder on the other server it works correctly, so I suspect the problem is with IIS.

 if (move_uploaded_file($_FILES ["file"] ["tmp_name"], "\\\\000.00.0.00\\tia\\web\\upload\\" .$_FILES["file"]["name"])) {
2
You need to show the PHP code you're using to handle the file, and an example of an exact error message.Pekka
Apologies. The code is quite simple: if (move_uploaded_file($_FILES ["file"] ["tmp_name"], "\\\\...IP address...\\tia\\web\\upload\\" .$_FILES["file"]["name"])) { There is no more to the error message apart from the line number of the code.LisaF
The problem doesn't lie in the code however, I believe it is with the setup of IIS.LisaF
@user can you edit it into the question and format it as code using the {} button? That's easier to read, thanks. Can you show the full code in the receiving script? Also, can you confirm that you are using a `\` network path?Pekka

2 Answers

2
votes

This has been covered already here. Quoting the reason here:

You have mapped target directory to a share such as \server2\files. These mappings are only available to the current users (eg, the admin account), not to the IUSR account that your php is probably running as (assuming IIS). Solution, don't use mappings, instead use the full 'unc' path name, ie '\server\share\folder\file.ext', also remember that the IUSR account will need access to these shares/folders/files

1
votes

From what I can see in your comment, you are using a \\ prefixed network share as the target for your move_uploaded_file() operation.

I'll bet a beer that PHP isn't allowed to access that share. Remember, PHP runs with IIS's permissions!

Try saving to a local, globally writable path first. If that works, you know you have to fix the share's permissions.