iis+php server cannot upload picture solution _php Tutorial

Source: Internet
Author: User
Tags php server temporary file storage ntfs permissions
The main purpose is to test my php.ini not set the value of Upload_dir_tmp, the uploaded files temporarily saved where, after this test found that the original php.ini upload_dir_tmp value is not configured, the default storage location is in C: Windowstemp directory, and the temporary file is stored with a. tmp suffix, the file is immediately deleted, so you want to modify the search function through the operating system files can not be found, you can not find the default path of Upload_dir_tmp.

iis+php Tutorial Server Unable to upload picture resolution

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.

Analysis:

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 (! @move_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 upload file set by itself

For some reasons such directory name works,
But the "upload_tmp" won ' t work.

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?

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, 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 there is this problem, while again in accordance with the above solution implementation, 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. The
cannot upload the file, does not mean that all the files cannot be uploaded, because one of my website, Flash calls fwrite () biography such as success, but call @move_uploaded_file ($f ["Tmp_name"], $dest _dir. . $fileName) This function is still not uploaded when the photo is transmitted.
After my analysis, because fwrite () is a binary file, and Move_uploaded_file () is a text file, and 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 analyze the upload.php file again and analyze the code that caused the failure as follows:

Check if a file is 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 filename:". $_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!";
}

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, it was found that the default storage location is in the C:windowstemp directory when the upload_dir_tmp value of the php.ini is not configured. and the temporary file is stored with a. tmp suffix, the file will be deleted immediately, so you want to modify the system through the file search function can not be found, you can not find the default path of Upload_dir_tmp.

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. This is why my multiple servers upload_dir_tmp values are empty when some can be transmitted, and some non-transmitting reasons.


http://www.bkjia.com/PHPjc/444754.html www.bkjia.com true http://www.bkjia.com/PHPjc/444754.html techarticle The main purpose is to test my php.ini not set the value of Upload_dir_tmp, the uploaded files temporarily saved where, after this test found that the original upload not configured php.ini ...

  • 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.