A workaround for using IIS-configured PHP in Windows to not upload files _win server

Source: Internet
Author: User
Tags configuration php temporary file storage
Continuation of the article "IIS configuration PHP in Windows Server 2003"
Server on the use of apache2+php normal operation, replaced by iis+php, there have been php.ini environment variables can not be read, PHP Verification code can not show the problem, and now someone can not upload pictures of the problem.

The process of replacing Apache2 from IIS is simply to turn on IIS, turn off the Apache2, nothing else changes, but there are so many differences, and there is a lot of variation in the way IIS supports PHP.
Analysis
According to the above description, I suspect that the problem is in the permissions configuration of IIS, the IUSR_MACHINE account does not write to the upload permission, so the permission to modify, the permissions under IIS, NTFS under the permissions are modified, but ultimately useless, look up the information on the network is not corresponding, To test the upload page, the process is:
SWF file calls save.php upload file---->swf file to rename the uploaded file---> name returned to the save.php---> Display the last name.

Now the problem stays with the SWF file renaming here, has not been to display the last name, and the SWF file does not participate in the upload process, You can only do the problem lookup in the save.php file, test in the file, the last name used by the variable is filename, and then insert the following statement to test:
echo "Filename=2008*****.gif";
The function of this sentence is to make the filename has a value, save.php can be normal display, the original statement of a sentence of the shielding test, all normal returned, but when the test to:
if (mailto:! @move_uploaded_file ($f [%22tmp_name], $dest _dir. '/'. $fileName)) header ("http/1.0 404 Not Found");
This sentence when the problem arises, can not upload, look up the context, has not found tmp_name variables, but see the meaning is to upload the file to a temporary file, and then move to the destination position, that this TMP position where? Is this location not writable,
To cause the file to be uploaded?
Find online information, found below PHP.ini 2 places on the upload configuration:
File_uploads = on here to set whether HTTP uploads are allowed, the default should be on
upload_tmp_dir= here set up the temporary location where the uploaded files are stored
The relevant information about these 2 places online is:
I try to set up file uploading under IIS 7 and PHP 5.
The problem is to set 2 variables in php.ini
File_uploads = ON//Here is the php.ini file, this place is set to ON
Upload_tmp_dir = "C:\Inetpub\wwwroot\uploads"//This path is the upload file you set up temporary storage path
For some reasons such directory name works,
But "upload_tmp" won ' t work.
The second problem is to set correct user rigths for upload folders where your try to save your file. I set my Upload folder rights for the ' workgroup/users ' for the full access. If you are experiment by yourselves if you are need execute access, for example.
My php.ini Upload_tmp_dir is commented, not enabled, but not set, but why Apache2 can be normal upload it? Is the problem really out here?

Solve
Create a new folder to do temporary upload directory, according to the English instructions above to modify the corresponding 2 items in the php.ini, temporary upload directory Upload_tmp_dir set up Powertrain folder, the folder to give "IUSR_ computer name" User can write, restart IIS, Upload to try, the problem is really so solved.

The final analysis of the answer
The above content is written in 09, but now July 2010 I added a server, and there is this problem, and again in accordance with the above solution to implement, in the process of operation is probably due to where the wrong, unexpectedly did not succeed, had to spare some time to study the specific reasons, The reasons for this problem are found as follows.
Unable to upload files, does not mean that all files can not upload, because one of my web site, Flash call Fwrite () biography, such as the success of the call @move_uploaded_file ($f ["Tmp_name"], $dest _dir. FileName) Such a function can still not be uploaded when the picture is passed.

After my analysis, the reason is that fwrite () is a binary file, and Move_uploaded_file () is a text file, and the Windows operating system is a description of the [Reference PHP manual Fwrite () function] that distinguishes the 2 files. This means that these 2 different files in the PHP environment when the upload of the temporary upload directory is different, because in the configuration of the IIS environment of PHP, set the temporary directory for E:\tmp, set up the directory of IUSR users can write, binary files can upload, So I suspect that the directory is the location where binaries upload temporary files, so where is the temporary file storage location for Move_uploaded_file () text files? In fact, the above paragraph in English, Upload_tmp_dir set the path is, but my several servers, the value of this setting for each server is commented out of the "no value", why some servers can upload, and some servers can not upload it? This is back to the previous question I raised, why Apache2 can upload and IIS can not upload it?
This time I analyze the upload.php file again, analyze the code that causes the fault in detail as follows:
Copy Code code as follows:

Check to see if any files are 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 2nd sentence in the normal code does not exist, in order to test the convenience I added, its main purpose is to test my php.ini did not set the value of the upload_dir_tmp, the uploaded file temporarily saved where, This test found that the default storage location was in the C:\windows\temp directory when the php.ini upload_dir_tmp value was not configured. and the temporary file is stored as a. tmp suffix, and the file will be deleted immediately, so you will not be able to find the UPLOAD_DIR_TMP's default path if you want to modify the search function through the operating system files.

Since we found the upload_dir_tmp default path, then modify the c:\windows\temp access, give IUSR_ user writable, restart the IIS Admin Service, upload files, finally succeeded. This is why I have multiple servers upload_dir_tmp values are empty when some can be transmitted, some of the reasons for not being transmitted.

You have now modified the article in which IIS uses environment variables to streamline the configuration of PHP, because it didn't pay attention to the permissions set at that point, causing today's problems, but the final solution is also good.

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.