Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP upload file inherit permissions error using Windows IIS Server

My colleague has been uploading files via PHP hosted on Windows Server 2008 IIS 7, but she's been having a problem downloading them, even though proper permissions on the upload folder are granted to the IIS_USRS group. Turns out the uploaded files aren't!

like image 636
peter n Avatar asked Oct 08 '12 17:10

peter n


People also ask

How do I fix windows server upload file inherit permissions?

In short, change the permissions on "upload_tmp_dir" (path in php. ini file) folder to match your web app folder permissions. If you cannot or do not want to change the permissions on the temp folder (the system temp folder by default). Then create a new temp folder and set the desired permission on that.

Can PHP run on Microsoft Windows IIS?

The fastest and easiest way to install PHP on Internet Information Services (IIS) is by using the Microsoft® Web Platform Installer (Web PI). Web PI completely automates setting up IIS, FastCGI, and the latest version of PHP from the php.net Web site.


2 Answers

In the hope that this might help someone else, I researched and found a solution here:

http://www.howyoudo.info/index.php/how-to-fix-windows-server-upload-file-inherit-permissions-error/

In short, change the permissions on "upload_tmp_dir" (path in php.ini file) folder to match your web app folder permissions.

If you cannot or do not want to change the permissions on the temp folder (the system temp folder by default). Then create a new temp folder and set the desired permission on that. Then update the PHP INI upload_tmp_dir value to point to that directory.

like image 59
peter n Avatar answered Nov 03 '22 02:11

peter n


Adding the content of the https://web.archive.org/web/20171121192635/http://www.howyoudo.info/index.php/how-to-fix-windows-server-upload-file-inherit-permissions-error/, in case this link goes unavailable in the future (thanks to comment from Tiffany).


How to fix PHP upload file inherit permissions error using Windows IIS Server

If you’re like me, and you use Windows IIS, you’ve spent hours trying to figure out why your uploaded file won’t inherit the permissions needed to display correctly.  Luckily, the answer is extremely easy and something most people would have never thought of.

The problem only happens when you use PHP to upload a file.  When you upload a file, PHP sends the file to a temporary directory on the hard drive (for me it is C:\Windows\Temp) and then copies it over to it’s intended directory.  Once the file has landed in the temporary directory, it is assigned the permissions of that directory. The problem is when Windows copies that file, it keeps the temporary directory’s permissions and doesn’t inherit your web directory’s permissions.

The easiest way to fix this problem is to add to the temporary directory your intended web directory’s permissions.  There’s no need to erase the permissions already in the temporary directory, just add the web directory’s permissions to them. In other words, follow these steps

  1. To change the permissions of your temporary upload directory, find the “upload_tmp_dir” in your php.ini file.
  2. Set it to the directory of your choosing (outside your web folders of course) or leave it at default (for me it is C:\Windows\Temp).
  3. Browse to this folder and add the permissions of your web folders to it.

That’s it!  As you can see, its really simple and just a little trick the guys at PHP forgot to tell us.

And just so you know, if the two folders were on separate drives, you wouldn’t have this problem, and thus wouldn’t be reading this.

like image 42
Alin3661 Avatar answered Nov 03 '22 04:11

Alin3661