Resolves an issue where PHP uploads pictures in Windows IIS is inaccessible

Source: Internet
Author: User
Tags configuration php

Recently in a Web site project encountered a very strange problem, is now recorded in hopes can help other friends problem Description: Recently the company has just bought a Hong KongWindows Server 2008 Server for unified management of a customer's n PHP Web siteThere are three websites on this server, one is a small esports website developed by thinkphp, a corporate website developed using WordPress, a mall mall developed using Ecshopbecause of the first two days of work, so leave to go back for a week (before you go three sites have been deployed to the server but the test is on the other server did not find any problems) after the return of leave the customer feedback a problem: all the site images uploaded after uploading can not be accessed ( previously uploaded images are normally accessed ), because it was tested before leaving and did not find a similar problem, but since the customer feedback that must be resolved, so a lengthy troubleshooting and processing stage  first log in to the site background to test found that the uploaded picture in the browser does not open and there is an unreachable error message: "401- Unauthorized: Access is denied due to invalid credentials. ” It then tested several other PHP projects on the server and found the same error: picture uploaded successfully, but browser does not have permission to accessBecause the test of a few PHP system is not the same, there are thinkphp,wordpress, Baidu Ueditor editor so the probability of these systems at the same time the problem is too small, so basically ruled out the program bug and see the above error to know that the file is there is no access to the permissions, so log on to the remote Desktop to the server to find the uploaded picture directory and found the picture of the test, the picture is uploaded successfully since the uploaded image can be accessed and the picture has been uploaded successfully, then why the new upload of the picture is not accessible? Then view the upload directory, directory permissions already contain "Everyone", directory should be no problem (previously uploaded images can be accessed)
And then a look at the picture properties of the test dumbfounded, the original picture of the properties do not containThe "Everyone" item does not match the permissions of the uploaded directory ( If you create a new file in a directory, the new file inherits the permissions of the directory)See this I can not understand, since the permissions of the directory hasThe "Everyone" Item then the permission to upload the picture should also inherit the permissions of the parent class, so for a long time did not want to understand the reasons for thisso also do not know how to solve, just on the network aimlessly see there are no similar problems, and follow the instructions of the site to try finally inWorkaround for PHP not uploading files under Windows using IIS configuration This article successfully resolves the issue summary: under the Windows platform if PHP is using IIS, then PHP uploads the file to a temporary directory, the first time the file is uploaded ( This configuration item can be configured in php.ini "Upload_tmp_dir" because our server is not configured, so PHP will use the system's Temp directory "C:\Windows\Temp")then PHP will then move the files uploaded in the temp directory to the directory you specified.So there is a problem, that is,The default permissions under the TEMP directory are not the appropriate IIS access permissions(Windows default configuration), the uploaded file is inherited by default when the file is uploaded to the directory.permissions for the temp directorywhen PHP then moves the file to the specified directory, the moved file does not inherit the directory permissions after the moveThis causes the moved file to be accessed from the browser because the file does not have the appropriate permissions (IIS access) and cannot access the normal questionThere was a successful upload of the file, but it appears when the browser accesses"401-Unauthorized: Access is denied due to invalid credentials. "The question Windows default Permissions configuration the changed permission configuration (must beinclude Iuser and Iis_iuserspermissions or Everyone )Workaround:
    1. Set a temporary directory for the Upload_tmp_dir item in php.ini and do the appropriate permissions ( recommended method )
    2. Add the appropriate permissions to the "C:\Windows\Temp" directory
Important notes:php.ini upload_tmp_dir directory permissions must contain Iuser and iis_iusers permissions or Everyone Reference: PHP is not able to upload files under Windows using IIS configuration php.ini not set Upload_tmp_dir, may cause upload failure, IIS host to a scheme, the official is not there is no way to iis+php, to resolve the upload file, Problem with empty directory

PHP Manual php.ini Configuration Upload-tmp-dir

Permissions issues for creating files under Windows

From for notes (Wiz)



Resolves an issue where PHP uploads pictures in Windows IIS is inaccessible

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.