Php+jquery Ajax Asynchronous upload picture (ajaxsubmit) Instance _php Tutorial

Source: Internet
Author: User
Let's take a look at a php+jquery Ajax asynchronous upload image (Ajaxsubmit) instance, which we really use Ajax instead of using IFRAME and the like.

The effect is as follows

The code is as follows Copy Code

index.php file

PHP in conjunction with jquery asynchronous upload picture (Ajaxsubmit), the following is the submission page code:





Ajax Upload Images asynchronously








Uploading files



doupfiles.php file

The code is as follows Copy Code

/*
* 1: Successful upload
*-1: file exceeds specified size
*-2: File type does not match
*-3: Error Moving file
*/
if (Is_uploaded_file ($_files[' upfile ' [' tmp_name '])) {

$photo _types=array (' image/jpg ', ' image/jpeg ', ' image/png ', ' image/pjpeg ', ' image/gif ', ' image/bmp ', ' image/x-png '); /define Upload Format
$max _size=700000; Upload photo size limit, default 700k
$photo _folder= "upload/". Date ("Y"). " /". Date (" M ")." /". Date (" D ")." /"; Upload photo path
Start processing uploads
if (!file_exists ($photo _folder))//check if the photo directory exists
{
mkdir ($photo _folder, 0777, true); mkdir ("Temp/sub, 0777, true);
}

$upfile =$_files[' upfile '];
$name = $upfile [' name '];
$type = $upfile [' type '];
$size = $upfile [' Size '];
$tmp _name= $upfile [' Tmp_name '];

$file = $_files["Upfile"];
$photo _name= $file ["Tmp_name"];
echo $photo _name;
$photo _size = getimagesize ($photo _name);

if ($max _size < $file ["size"])//Check File size
echo "-1"; echo "";
if (!in_array ($file ["type"], $photo _types)//Check file type
echo "-2"; echo "";
if (!file_exists ($photo _folder))//Photo catalogue
mkdir ($photo _folder);
$pinfo =pathinfo ($file ["name"]);
$photo _type= $pinfo [' extension '];//upload file name extensions
$photo _server_folder = $photo _folder.time (). ".". $photo _type;//with the current time and 7-bit random number as the file name, here is the full path of the upload


if (!move_uploaded_file ($photo _name, $photo _server_folder))
{
echo "-3"; echo "Error moving File";
Exit
}
$pinfo =pathinfo ($photo _server_folder);
$fname = $pinfo [' basename '];
echo "1"; echo "has successfully uploaded:". $photo _server_folder. "
";


}
?>

Finally the complete Php+jquery Ajax asynchronous upload image (Ajaxsubmit) instance source download address

http://www.bkjia.com/PHPjc/632888.html www.bkjia.com true http://www.bkjia.com/PHPjc/632888.html techarticle Let's take a look at a php+jquery Ajax asynchronous upload image (Ajaxsubmit) instance, which we really use Ajax instead of using IFRAME and the like. The following code works as follows ...

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