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
- To change the permissions of your temporary upload directory, find the “upload_tmp_dir” in your php.ini file.
- 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).
- 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.


- Average rating: 4.90 from 21 users























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.
Mike said
am December 24 2008 @ 2:25 pm
Thank you very much for this solution, how did you find this out?
Once again, a very big thank you.
Garon said
am December 24 2008 @ 3:41 pm
Hours and hours of searching. Glad I could help!
Jason said
am May 19 2009 @ 1:30 pm
Thank you very much. I was going crazy trying to figure this out. The funny thing is that this doesn’t happen with ASP.Net, so I was a bit baffled, I assumed the upload mechanism would be the same.
I’ll be linking to this article from my blog.
Jim said
am May 24 2009 @ 12:52 pm
THANK YOU!
This was killing me.
Juan Carlos Rois said
am July 17 2009 @ 1:05 pm
Garon,
Thanks a lot, I was about to loose it with this issue. I have a question though.
Your solution makes total sense, but what if you are not in control of the server and you don’t have access to the php.ini file.
I’m only asking because I could fix the issue just as you advice, except that the site is hosted by a third party company that probably won’t allow this changes or won’t even consider allowing anything to happen outside the root folder that your site is confined to.
Thanks.
Juan Carlos
Garon said
am July 20 2009 @ 1:18 pm
Juan, if your host is using Windows, just ask your host to add IIS permissions to the temporary PHP folder. That’s all I know to tell you to do.
Jon Shaw said
am January 29 2010 @ 7:54 am
Thank you for this.
My upload was doing a thumbnail and main photo. The thumbnail photo got the correct permissions, but not the main photo, which was strange (they were in different directories). Only wasted 2 hours, not loads more thanks to this.
Brian said
am January 30 2010 @ 6:36 pm
Thank God I didn’t spend hours on it, this saved me a lot of time. Thanks!
Jon Kragh said
am February 16 2010 @ 6:02 pm
Another thank you!
A big help!
Jon
Ben said
am February 24 2010 @ 5:00 am
THANKS A LOT!!!
THANKS A LOT!!!
THANKS A LOT!!!
THANKS A LOT!!!
THANKS A LOT!!!
THANKS A LOT!!!
I was going crazy about this PHP/IIS-upload behaviour.
Finally stumbled upon this page and indeed, didn’t think about the temp directories.
I owe you one.
Regards.
Tom said
am April 15 2010 @ 12:46 pm
You wrote:
“The easiest way to fix this problem is to add to the temporary directory your intended web directory’s permissions.”
How is this done exactly?!
Thank you!
Garon said
am April 25 2010 @ 4:54 pm
Basically, find your temp directory (look in your php.ini) and right click on it and go to the security tab. Open up another explorer window and right click on your IIS web folder and under the security tab, make them look the same (adding the same users/groups, etc). Hope this helps.
phpcmsworks said
am May 27 2010 @ 12:35 am
Hi ,
I tried to assign and configure permission to the temp directory but still i am facing error.
I changed the my tmp directory to D:\tmp location
Can anyone please explain the configuration of the permission to upload a file in IIS server.
I am using IIS server 5.1 version.
Any suggestion to solve my problem.
Thanks
Garon said
am May 27 2010 @ 6:19 am
I’ve read that if you change your temp directory to a different drive, it will inherit the correct permissions when it copies the files over to your IIS directory. To give your temp directory the right permissions, all you do is add modify rights to the IUSR_ user. In some cases, I’ve also had to give modify rights to the IIS_WPG user as well, but you can play with it and see for yourself. That should take care of it.
phpcmsworks said
am June 1 2010 @ 5:53 am
Hi Garon,
Thanks a lot for your reply …
I tried all possibility but still i am unable to resolve my problem.
These are list of changes i made for uploading function:
1)In php.ini file, i modified upload_tmp_dir=”C:/Inetpub/tmp” & set permission to the tmp folder by right click on the folder and select properties items under that i enable write,read,execute option
2)I set IUSR_MachineName write,read,execute permissions
3)I set default website folder write,read,execute permissions
Please let me know if i made any wrong configuration &it would be great help for me.
Thanks
Garon said
am June 1 2010 @ 3:39 pm
First of all, make sure PHP recognizes the new tmp directory. Put this code in a .php file < ?php phpinfo(); ?>, scroll down to the upload_tmp_dir and make sure it matches what you think it does. Once you’ve verified that, add the IIS_WPG user and give him the right permissions. If all else fails, add the Everyone user to all folders involved. If that still doesn’t work, perhaps its a bug in IIS 5.1 (I’m using 6.0). Just to be clear, you are adding IUSR_MachineName to the tmp directory with the right permissions, right?
phpcmsworks said
am June 2 2010 @ 6:18 am
Hi Garon,
Thanks alot i got the soloution…
I faced problem due the permissions iis user only ,but my system is configured in LAN network so if i set permission to the IUSR_Machinename user also it is overrides by main administrator.
So i create a new user to the my system with full permission and follow above setting in the blog.
There will not be any problem if ur machine is local system & follow above setting for the user.
Thank again Gardon.
T
Hoborg said
am July 7 2010 @ 5:17 am
I’m using XAMPP and I had this problem with uploaded files… i found the temp directory of xampp in C:\xampp\php\php.ini ‘s upload_tmp_dir and it was C:\xampp\tmp\ ; and now everything is working great withou even 1 problem…
Thank You A Lot A Lot Much More Than A Lot…
I don’t know how to thank you for your helpful post… ;’)
Michael Walsh said
am August 27 2010 @ 3:19 am
Massive thank you! That has resolved the problem.
WordPress URL Rewrite Module Error 500.50 on IIS7 » bloing.net said
am October 8 2010 @ 2:13 am
[...] images in your blog posts, you will probably encounter this error. The cause, as detailed here and here, is a permissions problem. When you upload files using PHP they are placed into a temporary [...]
mitja.GTI said
am October 13 2010 @ 6:08 pm
OMG! You have saved my life
Thanks!
Dennis said
am October 14 2010 @ 12:52 am
This exactly what I needed. However, just a note, in php 5.3, there are 2 instances of upload_tmp_dir in php.ini, and you need to change them both (and possibly restart the server ( i needed to for iis7.5)) for this to work.
Moodle Uploaded File Permissions Issues said
am November 30 2010 @ 10:28 pm
[...] the two folders were on separate drives, you wouldn’t have this problem…” (How to fix PHP upload file inherit permissions error using Windows IIS Server | HowYouDo.Info) I’ve moved the temp directory (in PHP.ini) from D:temp (D: drive is where moodledata [...]
Wordpress Windows 2008 Web Server R2 IIS 7.5 setup – Amixa Blog - Professional Web Site Design Experts said
am January 7 2011 @ 2:07 pm
[...] [...]
Software Development said
am February 9 2011 @ 5:08 am
Awesome post. after a long time i had read an awesome written post.
Dermot Ryan said
am February 11 2011 @ 7:39 am
Here is an even simpler solution:
Use copy() instead of move_uploaded_file().
Copy appears to reset the permissions while move uploaded retains them!
wilson said
am April 6 2011 @ 8:51 am
Thanks. This did it for me!
Dave in Dallas said
am April 7 2011 @ 8:40 pm
Garon, you rock! Our WordPress/PHP permissions were not quite right after a server restore from crash, but this fixed our biggest problem. REALLY appreciate it!
Bartek Poland said
am April 28 2011 @ 12:29 pm
Thank you
IIS WordPress images 500 error – Amixa Blog - Professional Web Site Design Experts said
am April 29 2011 @ 1:19 pm
[...] [...]
Jim Hainsworth said
am May 3 2011 @ 5:59 pm
This was driving me crazy. We had it all working then the server had a power failure and the upload error returned.
Still not sure why that happened but finally with your blog was able to get the PHP to work on the 2008 R2 server running IIS 7.5. Odd thing was when it workied the first time we didn’t need the IIS_WPG user, now that users permissions has fixed it.
Jim Hainsworth said
am May 6 2011 @ 8:59 am
I guess I was premature in the congratulations.
I am still getting the error.
There is a reference to needing to add the temp folder in two places, can anybody tell me where the second config file is?
I have added the silverstripe-cache upload_tmp_dir variable to the _config.php in my sites folder.
Lee said
am May 26 2011 @ 4:43 pm
You learn something new everyday
As an asp.net developer some php packages have been confusing me with this damn issue!
Elena Webba said
am May 31 2011 @ 1:46 am
thank you!
You save my life
I can finish my blog now, anch tomorrow I can go to the beach!
Richard said
am June 21 2011 @ 7:07 am
you are divine
Naval Kishore said
am June 30 2011 @ 1:10 pm
Thank you very much to all for sharing experiences, efforts and answers. I am using IIS 7.5, PHP 3.5.6 and MySQL 5.5.
student said
am June 30 2011 @ 4:55 pm
thanks a lot and it should be better if you provide a video
i think you saved my life
Srinaath said
am August 3 2011 @ 8:43 am
u r awsum
Diogo Raminhos said
am October 28 2011 @ 4:13 am
I subscribe to Ben’s words:
“THANKS A LOT!!!
THANKS A LOT!!!
THANKS A LOT!!!
THANKS A LOT!!!
THANKS A LOT!!!
THANKS A LOT!!!”
I was getting crazy with the 500 error page on each upload…
Fabiano Alves said
am December 2 2011 @ 6:49 am
You rock man!!!
Thanks!!!
Virginia said
am December 14 2011 @ 11:03 am
I am super glad I found this thread – I was getting that 500 error with uploading PDFs through Joomla’s media manager on an IIS7.5 install, and matching the permissions on my web directory and temp directory completely fixed the problem. Thanks!
Easier solution said
am February 3 2012 @ 5:36 pm
Rather than muck around with permissions – agree with Dermot – use copy() rather than move_uploaded_file(). I’m running Apache on Windows and it worked perfectly for me.
Abhi said
am February 24 2012 @ 8:30 am
Great man !
God bless U !
Tnx a ton
sb said
am March 1 2012 @ 5:50 am
GRANDE, BRAVO, GRAZIE
jake said
am March 23 2012 @ 10:07 am
bless you.
dave said
am April 17 2012 @ 8:29 pm
fixed my problem too
iis php curl rest api. http://stackoverflow.com/questions/10201274/php-curl-upload-image-on-iis-7-image-not-completely-uploaded
Tom Powley said
am April 26 2012 @ 4:23 am
Thank You!!! You saved our schools website!
I was pulling my hair out on this one…
I found useful info from Joomla docs regarding setting the website’s directory and file system permissions correctly on IIS:
http://docs.joomla.org/IIS
This fixed some issues but uploading files and trying to view them still caused an error, after looking into the file permissions on the uploaded files I found the permission were not being pick up, after a bit of searching on the web I found this page. I set the correct permissions on the C:\Windows\Temp folder, re-uploaded a document and everything now works perfectly.
Once again… A Huge Thank You!
Manender SIngh said
am May 16 2012 @ 7:19 am
Thanks a ton…… u r great