The image upload function always prompts two exceptions.
Source: Internet
Author: User
The image upload function always prompts two rows of errors. The image upload function always prompts two rows of error: Notice: Undefinedindex: uploadinD: \ WWW \ qiangyuan \ up. phponline34Notice: when Undef uploads an image, two lines of errors are always prompted.
The image upload function always prompts two rows of errors:
Notice: Undefined index: upload in D: \ WWW \ qiangyuan \ up. php on line 34
Notice: Undefined index: upload in D: \ WWW \ qiangyuan \ up. php on line 41
The code is as follows:
/**
* $ File_ext: format of the uploaded file image;
* $ File_name: After the upload, a new path and file name exist on the server;
*/
If ($ _ FILES ["upload"] ["size"]> 0)
{
// Specify the format of the uploaded file
If ($ file_ext = "jpg" | $ file_ext = "jpeg" | $ file_ext = "gif" | $ file_ext = "png ")
{
If ($ _ FILES ["upload"] ["size"] <400000) // The image size cannot exceed 400 KB.
{
$ File_name = "./". date ("YmdHis ");
$ File_name. = ".". $ file_ext;
$ Tmp_name = $ _ FILES ["upload"] ["tmp_name"];
Move_uploaded_file ($ tmp_name, "product/$ file_name"); // upload to the image directory
Echo substr ($ file_name, 2); // name of the image generated by the output
Echo"
";
Echo "";
}
Else
{
Echo "the size of the uploaded file image must be smaller than kB ";
}
}
Else
{
Echo "the format of the uploaded file is incorrect ";
}
}
?>
------ Solution --------------------
Discussion
The image upload function always prompts two rows of errors:
Notice: Undefined index: upload in D: \ WWW \ qiangyuan \ up. php on line 34
Notice: Undefined index: upload in D: \ WWW \ qiangyuan \ up. php on line 41
The code is as follows:
------ Solution --------------------
Determine $ _ FILES ['upload'] ['error'] = '0' to see if it has been uploaded to php.
You can also view the parameters in print_r ($ _ FILES) before using $ _ FILES.
------ Solution --------------------
Discussion
First, you must determine whether the form has been submitted. if a file has been uploaded, you can process it again:
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