Do a picture upload function, always prompt two lines of exception

Source: Internet
Author: User
Do a picture upload function, always prompt two lines of error.
Do a picture upload function, always prompt two lines of error:
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: Upload the file image format;
* $file _name: After uploading, there is a new path and file name 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)
{
Limit the uploaded file format
if ($file _ext = = = "JPG" | | $file _ext = = "JPEG" | | $file _ext = = "gif" | | $file _ext = = "png")
{
if ($_files["Upload" ["Size"] < 400000)//Picture size cannot be greater than
{
$file _name = "./". Date ("Ymdhis");
$file _name. = ".". $file _ext;

$tmp _name = $_files["Upload" ["tmp_name"];
Move_uploaded_file ($tmp _name, "product/$file _name"); Upload to Picture directory

Echo substr ($file _name,2);//output generated picture name

echo "

";
echo "";

}
Else
{
echo "Upload file image size must be less than 400kb";
}
}
Else
{
echo "uploaded file format is incorrect";
}
}
?>



------Solution--------------------
discuss
Do a picture upload function, always prompt two lines of error:
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--------------------
Judge $_files[' upload ' [' error '] = = ' 0 ' to see if it has been uploaded to PHP.

You can also print_r before using $_files ($_files); View the parameters.
------Solution--------------------
Explore

To determine whether the form has been submitted, if there are files uploaded and then processed:

PHP Code
if (isset ($_files[' upload ')} {
$file _ext = $_files["Upload" ["name"];
$file _ext_rev = Strrev ($file _ext);
$file _ext_num = Strrpos ($file _ext ...
  • 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.