PHP in Windows IIS uploaded Picture unreachable solution _win Server

Source: Internet
Author: User

PHP in Windows IIS uploaded pictures can not access the solution

First log into the background of the Web site to test found that the uploaded picture is not open in the true browser and an unreachable error message: "401-Unauthorized: Access is denied due to invalid credentials." ”

Then I tested several other PHP projects on the server and found that the same error occurred: The picture was uploaded successfully, but the browser did not have permission to access it.
because the test of several PHP system is not the same, there are thinkphp,wordpress, Baidu Ueditor editor.
So the probability of these systems having problems at the same time is too small, so basically eliminate the bug of the program, and see the above error to know that the file is there is no access to the right, so log into the remote Desktop to the server to find uploaded pictures directory and found the test pictures, the picture is uploaded successfully.
Since the uploaded images can be accessed and the pictures uploaded successfully, why are the new uploaded images not accessible?
So look at the upload directory, directory permissions already include "Everyone", the directory should also have no problem (previously uploaded images can be accessed)

Then a look at the test picture properties dumbfounded, the original picture properties does not contain the "Everyone" item this is not consistent with the permissions of the uploaded directory ah (if you create a new file in a directory, the new file is the right to inherit the directory)

See this I do not understand, since the directory permissions have "Everyone" item then upload the permissions of the picture should also inherit the permissions of the parent class, so for a long time did not want to understand the reasons for this, so also do not know how to solve, but on the internet aimlessly see there is no similar problem, and follow the instructions on the website to try.

Finally, the solution for using IIS-configured PHP in Windows to not upload files with the help of this article was successfully solved


Summary of questions:
If PHP is using IIS under the Windows platform, PHP uploads the file to a temporary directory before uploading it.
(This configuration item can be configured in PHP.ini's "Upload_tmp_dir", because our server has not been configured, PHP will use the system's temporary directory "C:\Windows\Temp").

PHP then moves the files uploaded in the temp directory to the directory you specified, which means that the default permissions in the TEMP directory are not the appropriate IIS access permissions (Windows default configuration). Files uploaded to the directory by default are inherited from the Temp directory permissions, when PHP moves the file to the specified directory, the moved file does not inherit the directory permissions that were moved, causing the file to be moved from the browser because the file does not have the appropriate permissions ( IIS access rights) and unable to visit the normal ask, there is a file upload successful but browser access appears "401-not authorized: Access is denied due to invalid credentials." "The question.

Windows default Permissions Configuration

Changed permission configuration (must include Iuser and Iis_iusers permissions or Everyone)

Solution:
set up a temporary directory for the Upload_tmp_dir item in php.ini and do the appropriate permissions (recommended method)
Add the appropriate permissions to the "C:\Windows\Temp" directory
Important NOTE:
PHP.ini Upload_tmp_dir directory permissions must include Iuser and Iis_iusers permissions
or everyone

The above is the entire content of this article, I hope to help you learn.

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.