IIS+php server cannot upload images solution_PHP tutorial

WBOY
Release: 2016-07-20 11:10:02
Original
751 people have browsed it

The main purpose is to test where the uploaded files are temporarily stored when the value of upload_dir_tmp is not set in my php.ini. After this test, I found that when the value of upload_dir_tmp in php.ini is not configured, the default storage location is C:windowstemp directory, and the temporary file is stored with the .tmp suffix. The file will be deleted immediately, so if you want to use the file modification search function of the operating system, it cannot be found, and it cannot be found. The default path of upload_dir_tmp is where.

IIS+php tutorial server cannot upload images solution

The server uses Apache2+PHP to run normally, and then changed to IIS+PHP. The environment variable of php.ini cannot be read successively. Verify in php The code cannot be displayed, and now some people have reported the problem of being unable to upload pictures.

The process of replacing Apache2 from IIS is just to open IIS and close Apache2. There are no other changes, but there are so many differences. It seems that IIS still needs to make many modifications to support PHP.

Analysis:

Based on the above description, I suspect that the problem lies in the permission configuration of IIS. The IUSR_MACHINE account does not have write permissions for upload, so I modified the permissions and set the permissions under IIS. , the permissions under NTFS were modified, but in the end it was useless. There was no corresponding search for information on the network. Test the upload page. The process is:

The swf file calls save.php to upload the file-- -->swf file renames the uploaded file--->The name is returned to save.php--->The last name is displayed.

The current problem has been stuck in the renaming of the file by swf. The last name has not been displayed, and the swf file does not participate in the upload process, so the problem can only be found in the save.php file. Now, test in this file. The variable used for the last displayed name is fileName, so insert the following statement for testing:

echo "fileName=2008*****.gif";

The function of this sentence is to make fileName have a value, and save.php can be displayed normally. First, the original statement is shielded and tested sentence by sentence, and everything is returned normally, but when the test reaches:
if ( !@move_uploaded_file($f["tmp_name"], $dest_dir.'/'.$fileName)) header("HTTP/1.0 404 Not Found");
A problem occurred when saying this, and it cannot be uploaded. Searching the context, I have never found the tmp_name variable, but it seems that the file is uploaded to a temporary file first, and then moved to the destination location. So where is the tmp location? Is it because this location is not writable that the file cannot be uploaded?

Searching for online information, I found that there are 2 places under php.ini for upload configuration:
file_uploads = On                                                                                                                            file_uploads =     ​​Set here Temporary location for storing uploaded files

Relevant information about these two places on the Internet are:

I try to set up file uploading under IIS 7 and PHP 5.

First problem was to set 2 variables in php.ini

file_uploads = On //This means that the php.ini file is set to On

upload_tmp_dir = "C:Inetpubwwwrootuploads" //This path is set by yourself Temporary storage path for uploaded files

For some reasons such directory name works,

but "upload_tmp" won't work.

The second problem was to set correct user rigths for upload folders where you try to save your file. I set my upload folder rights for the "WORKGROUP/users" for the full access. You may experiment by yourselves if you not need execute access, for example.

My php The upload_tmp_dir in the .ini is commented, not enabled, and not set. But why can Apache2 upload normally? Is this really the problem?

Solution:

Create a new folder as the temporary upload directory, modify the corresponding two items in php.ini according to the English instructions above, and set the temporary upload directory upload_tmp_dir to the file just created folder, grant the permissions of the folder to "IUSR_computer name" to be writable by the user, restart IIS, try uploading, and the problem is really solved.

Final analysis answer:

The above content was written in 2009, but now in July 2010, I added a new server and this problem occurred again. At the same time, I implemented the above solution again. During the operation, something probably went wrong. Wrong, it didn't work. I had to take some time to study the specific reasons, and found the following reasons for the problem.
Being unable to upload files does not mean that all files cannot be uploaded, because on one of my websites, flash calls fwrite() to transfer avatars and the like successfully, but calling @move_uploaded_file($f["tmp_name"], $dest_dir. '/'.$fileName) still cannot be uploaded when using a function like this to transfer photos.
After my analysis, the reason is that fwrite() transfers a binary file, while move_uploaded_file() transfers a text file, and the Windows operating system distinguishes between these two types of files [Refer to the PHP manual for the fwrite() function Note], which means that the temporary upload directories stored when these two different files are uploaded in the PHP environment are different. When configuring PHP in the IIS environment, the temporary directory is set to E:tmp. The directory is writable by the iusr user, and binary files can be uploaded, so I suspect that this directory is the storage location for temporary files for binary file upload. So where is the temporary file storage location for the text file passed by move_uploaded_file()? In fact, in the above paragraph in English, the path set by upload_tmp_dir is the path. However, among several of my servers, the value of this setting of each server is the commented out "no value". Why can some servers upload? , but some servers cannot upload? This also goes back to the question I asked before, why can Apache2 can upload but iis can't?
This time I analyzed the upload.php file again and analyzed the code that caused the failure. The specific content is as follows:

// Check whether there is a file uploaded
if (! $_FILES['upload'. $num]['name'] == ""){
if ($_FILES['upload'.$num]['size'] < $max_size) {
1. echo "File upload path : ".$location.$_FILES['upload'.$num]['name'];
2. echo "File temporary file name: ".$_FILES['upload'.$num]['tmp_name' ];
3. move_uploaded_file($_FILES['upload'.$num]['tmp_name'],$location.$_FILES['upload'.$num]['name']) or $event = "Failure ";
} else {
$event = "File too large!";
}

The second sentence in the normal code does not exist. I added it for the convenience of testing. , its main purpose is to test where the uploaded files are temporarily stored when my php.ini does not set the value of upload_dir_tmp. After this test, I found that when the value of upload_dir_tmp in php.ini is not configured, the default storage The location is in the C:windowstemp directory, and the temporary file is stored with the .tmp suffix. The file will be deleted immediately, so you cannot find it through the file modification search function of the operating system, and you cannot find upload_dir_tmp. Where is the default path.

Now that the default path of upload_dir_tmp has been found, modify the access permissions of c:windowstemp, make it writable by the IUSR_ user, restart the IIS Admin service, upload the file, and finally succeed. This is why when the upload_dir_tmp values ​​of multiple servers of mine are all empty, some can be transferred and some cannot.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444754.htmlTechArticleThe main purpose is to test where the uploaded files are temporarily saved when my php.ini does not set the upload_dir_tmp value. Yes, after this test, it was found that the upload of php.ini was not configured...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!