iis+php server cannot upload picture (500 error)

Source: Internet
Author: User
Tags php server temporary file storage vars ntfs permissions

If the form cannot be submitted properly, modify the temporary file permissions ~ ~ ~ If you can submit the form normally, modify the upload file Small!!!

Server on the use of apache2+php normal operation, replaced by Iis+php, has appeared php.ini environment variables can not be read, PHP verification code can not display the problem, and now some people respond to the problem of uploading pictures.

The process of replacing Apache2 from IIS is just to turn on IIS, turn off Apache2, and nothing else, but there are so many differences that it seems that IIS supports PHP with a lot of changes.


According to the above description, I suspect that the problem is in the IIS permissions configuration, Iusr_machine account to upload do not write permissions, so the permissions to modify, permissions under IIS, NTFS permissions are modified, but ultimately useless, find information on the network is not corresponding, To test the upload page, the process is:

The SWF file calls the save.php upload file---->swf file to rename the uploaded file---> The name returned to save.php---> shows the last name.

Now the problem is stuck in the SWF rename file here, has not been to show the last name, and the SWF file does not participate in the upload process, Then you can only do a problem lookup in the save.php file, test it in the file, and then insert the following statement to test that the last name used is filename:

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

The function of this sentence is to make filename has a value, save.php can be normal display, the original sentence of one sentence of the screening test, are normal return, but when the test to:

if ([email Protected]_uploaded_file ($f ["Tmp_name"], $dest _dir. '/'. $fileName)) header ("http/1.0 404 Not Found");

This sentence when the problem arises, can not upload, look for 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, then this TMP location where? Is this location not writable, resulting in the inability to upload files?

Find the information on the Internet and discover the php.ini below there are 2 places about the upload configuration:

File_uploads = On here sets whether to allow HTTP uploads, which should be on by default

upload_tmp_dir= here set the temporary location where the uploaded files are stored

Information about these 2 places is available online:

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

First problem is to set 2 variables in php.ini

File_uploads = ON//Here is to say php.ini file This place is set to ON

Upload_tmp_dir = "C:inetpubwwwrootuploads"//This path is the temporary storage path of the uploaded files that you set.

  1. For some reasons such directory name works,
  2. But the "upload_tmp" won ' t work.
  3. The second problem is to set correct user rigths for upload folders where do try to save your file. I set my Upload folder rights for the ' workgroup/users ' for the full access. Experiment by yourselves if you are not need execute access, for example.

My php.ini Upload_tmp_dir is commented, not enabled, but not set, but why Apache2 can normally upload it? Does the problem really come out here?


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, the temporary upload directory upload_tmp_dir settings powertrain to set up the folder, the folder permissions to the "IUSR_ computer name" User can write, restart IIS, Upload try, the problem is really solved.

The final analytical answer:

The above content is written in 09, but now in July 2010 I added a server, and this problem, and again in accordance with the above solution to implement, in the process of operation is probably due to what went wrong, unexpectedly did not succeed, had to spare some time to study the specific reasons, The reasons for this problem are found below.

Unable to upload the file, does not mean that all the files can not be uploaded, because one of my website, Flash call fwrite () upload avatar such as success, but call @move_uploaded_file ($f ["Tmp_name"], $dest _dir. '/'. $ FileName) is still not uploaded when the function is transmitting a photo.

After my analysis, the reason is because fwrite () is a binary file, and Move_uploaded_file () is a text file, while the Windows operating system is to distinguish between the 2 kinds of files [refer to the PHP manual fwrite () function description], This means that these 2 different files in the PHP environment upload the temporary upload directory is different, because in the configuration of PHP in the IIS environment when the temporary directory is e:tmp, set the directory of IUSR user writable, binary files can be uploaded, So I suspect that this directory is the storage location of the temporary file where the binary files are uploaded, so where is the temporary file storage location for the move_uploaded_file () text file? In fact, in the above paragraph in English, Upload_tmp_dir set the path is, but my several servers, each server's value of this setting is commented out "No value", why some servers can be uploaded, and some servers can not upload it? This also goes back to the question I raised before, why Apache2 can be uploaded and IIS can not upload it?

This time I analyzed the upload.php file again and analyzed the code that caused the failure as follows:

  1. Check if a file is uploaded
  2. if (! $_files[' upload '. $num [' name '] = = "") {
  3. if ($_files[' upload '). $num [' size '] < $max _size) {
  4. 1, echo "File Upload path:". $location. $_files[' upload '. $num [' name '];
  5. 2. Echo "file temp filename:". $_files[' upload '. $num [' Tmp_name '];
  6. 3, Move_uploaded_file ($_files[' upload '). $num [' Tmp_name '],$location. $_files[' upload '. $num [' name ']) or $event = "Failure";
  7. } else {//Open source code template zuimoban.com
  8. $event = "File too large!";
  9. }

Where the normal code in the 2nd sentence is not present, in order to test the convenience I added, its main purpose is to test my php.ini not set the value of Upload_dir_tmp, the upload of the file temporarily saved where, After this test found that the original value of the UPLOAD_DIR_TMP is not configured php.ini, the default storage location is in the C:windowstemp directory, and the temporary file is stored with a. tmp suffix, the file will be deleted immediately, So you want to modify the search function through the operating system files can not be found, you can not find the upload_dir_tmp default path is where.

Now that we have found the default path of upload_dir_tmp, then modify the access rights of c:windowstemp, give IUSR_ user the ability to write, restart the IIS Admin Service, upload the file, and finally succeed, which is why I have multiple servers upload_dir_ The value of TMP is empty when some can be transmitted, and some non-transmitting reasons.

Reprint: http://www.zuimoban.com/php/php/4370.html

iis+php server cannot upload picture (500 error)

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.