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.

Rate This Post: 1 Star2 Stars3 Stars4 Stars5 Stars - Average rating: 4.64 from 64 users

122 Comments so far »

  1. anusha said

    am December 19 2015 @ 8:49 am

    thanks man… solved it with simple steps,looking for this for hours

  2. IIS WordPress images 500 error – TechnoRADAR said

    am December 25 2015 @ 1:06 pm

    […] sweat it, I will save you HOURS of time on this one.   Thanks to the article I found here after HOURS of tracking this issue down, this problem is caused because PHP first uploads the […]

  3. Don said

    am December 30 2015 @ 4:31 pm

    How simple and effective. I’m very happy to have found your simple solution to a vexing problem. Many thanks.

  4. Brian O'Sullivan said

    am February 25 2016 @ 7:19 am

    Thank you, this could have taken ages to find. Thanks again. Brian

  5. Emiliano said

    am April 12 2016 @ 9:24 am

    Man, it’s 2016 and you continue saving the day!

    Thank you very much!

  6. shiva manhar said

    am April 19 2016 @ 7:19 am

    Thanks a lot. It solved my problem by configuring in php.ini file.

  7. João Lúcio Duarte (Brasil) said

    am May 15 2016 @ 3:52 am

    Muito obrigado.
    Foi muito valioso.

    Thank you.

  8. ATech said

    am June 29 2016 @ 10:34 am

    You have saved my day!

  9. Andres Cavallin said

    am July 14 2016 @ 7:39 am

    Thanks very much!!! This solved a great issue

  10. Maxime Bescu said

    am August 19 2016 @ 8:38 am

    Thank you very much, I search the solution for hours!!!

  11. Phil said

    am September 19 2016 @ 5:11 am

    your a life saver mate

  12. nwillo said

    am October 12 2016 @ 8:03 am

    Thanks alot. I was searching for this for a long time. Keep doing the good work. (y)

  13. Ben Roberts said

    am December 22 2016 @ 10:04 am

    OMG!!! I’ve spent three days trying to work this out! Email me a donation link – I need to buy you a beer!

  14. Yunus Emre said

    am March 16 2017 @ 3:10 pm

    Thank you very very very much!

  15. IIS WordPress Uploaded Files 500 Error | henrywrites said

    am April 20 2017 @ 9:53 pm

  16. Andrea said

    am April 21 2017 @ 1:55 am

    Thanks a lot. It’s now 2017 and keep being useful 😉
    By the way, I would like to point out the copy+delete method and ask Garon what does he think about it. Can you suggest to use it or are there any drawbacks? Thank you!

  17. Michael C. said

    am June 6 2017 @ 12:35 pm

    Very good, thanks!

  18. Setting up a Photographic Portfolio in WordPress – Vast said

    am December 29 2017 @ 12:45 am

    […] when I went to click on the images to view full screen in pop-up a lot of the images do not show. This article explains what is happening and tells you how to solve it. The Temp file on the server has certain […]

  19. imran said

    am January 12 2018 @ 6:21 am

    Thank you very much, I search the solution for 1 day!!!

  20. Oscar Ramirez said

    am February 7 2018 @ 8:23 am

    2018… still helpfull

  21. Carlo said

    am February 9 2018 @ 1:42 am

    Thank you so much!
    I spent four days browsing the whole stackoverflow, looking for a solution!
    And it was so simple!
    Thanks again!

  22. Geeves said

    am March 7 2018 @ 8:22 am

    Thank you! A recent windows update change the permissions and your tip restored it. Thank you!

Comment RSS · TrackBack URI

Leave a comment

Name: (Required)

eMail: (Required)



Comments links could be nofollow free.