Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission Denied on move_uploaded_file to another server in IIS

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"])) {
like image 398
LisaF Avatar asked Dec 16 '25 16:12

LisaF


2 Answers

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

like image 76
shamittomar Avatar answered Dec 19 '25 04:12

shamittomar


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.

like image 40
Pekka Avatar answered Dec 19 '25 04:12

Pekka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!