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