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.  In other words, don’t erase the permissions already in the temporary directory, just add the web directory’s permissions to them.  If you want to change your temporary upload directory, find the “upload_tmp_dir” in your php.ini file and set it to the directory of your choosing (outside your web folders of course), and then add the proper permissions.  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.  So as you can see, its really simple and just a little trick the guys at PHP forgot to tell us.


1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

1 Comment so far »

  1. Ben said

    am October 22 2008 @ 12:06 pm

    Thanks! That makes sense but would have taken much longer to find if you hadn’t provided this explanation.

Comment RSS · TrackBack URI

Leave a comment

Name: (Required)

eMail: (Required)

Website:

Comment:


Comments links could be nofollow free.