Foreground HTML jquery code background PHP processing
Foreground HTML
图片上传
* * Note that the name is written by using the name[] method and using the same name
* * Note the form with file, form must add: enctype= "Multipart/form-data"
jquery Submit Form Form
$(#form).form('submit',{
url:url,
success:function(data){
//处理返回数据
}
});
php background processing
//receive processing file $fileArray = $_files[' Imagesupload '];//gets the file according to the requested name $upload _dir = Public_path ().
/upload/carpic/;
$userID = Session::get (' UserID ');
$nowTime = Date (Ymdhis, Time ());
$i = 0;
$successName = Array (); foreach ($fileArray [' Error '] as $key => $error) {//Traversal process file if ($error = = UPLOAD_ERR_OK) {$temp _name = $FILEARR
ay[' Tmp_name ' [$key];
$file _name = $userID. $nowTime $i. $fileArray [' name '] [$key];
Move_uploaded_file ($temp _name, $upload _dir. $file _name); Array_push ($successName, $file _name)//Add the uploaded file name to the array}else{return ' {flag:0,flagmsg: Upload [file '. $key. ']
Failure!!} ';
} $i + +;
$flag = Array (' flag ' =>1, ' flagmsg ' => ' file uploaded successfully! ');
$names = Array (' names ' => $successName); Return Json_encode ($flag, $names))//returns the upload result and returns the name of all files after the successful upload
PHP code is very simple, not explained. Welcome to guide!