The image upload function always prompts two rows of errors. The image upload function always prompts two rows of error: Notice: Undefinedindex: uploadinD: WWWqiangyuanup. phponline34Notice: Undefinedindex: uploadinD: WWWqiangyuanup. phponline41 implements an image upload function, which always prompts two rows of errors.
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;
*/
$ File_ext = $ _ FILES ["upload"] ["name"];
$ File_ext_rev = strrev ($ file_ext );
$ File_ext_num = strrpos ($ file_ext_rev ,".");
$ File_ext = strrev ($ file_ext_rev );
$ File_ext = substr ($ file_ext,-$ file_ext_num );
$ File_ext = strtolower ($ file_ext );
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:
PHP code
If (isset ($ _ FILES ['upload']) {
$ File_ext = $ _ FILES ["upload"] ["name"];
$ File_ext_rev = strrev ($ file_ext );
$ File_ext_num = strrpos ($ file_ext ......