Plug-in and source code can be downloaded here http://www.jq22.com/jquery-info5231
The following is supplemented by the downloaded demo:
Use bootstrap interface beautiful, can preview, can drag upload, can cooperate with Ajax asynchronous or synchronous upload, the following is:
Front-end Code: fileinput.html
<!DOCTYPE HTML><!--release v4.1.8, copyright 2014-2015 Kartik Visweswaran -<HTMLLang= "en"> <Head> <MetaCharSet= "UTF-8"/> <title>Bootstrap Multi-image upload</title> <Linkhref= "/public/index/fileinput/css/bootstrap.min.css"rel= "stylesheet"> <Linkhref= "/public/index/fileinput/css/fileinput.css"Media= "All"rel= "stylesheet"type= "Text/css" /> <Scriptsrc= "/public/index/fileinput/js/jquery-2.0.3.min.js"></Script> <Scriptsrc= "/public/index/fileinput/js/fileinput.js"type= "Text/javascript"></Script> <Scriptsrc= "/public/index/fileinput/js/bootstrap.min.js"type= "Text/javascript"></Script> <!--Chinese Culture - <Scriptsrc= "/public/index/fileinput/js/fileinput_locale_zh.js"type= "Text/javascript"></Script> </Head> <Body> <Divclass= "Container Kv-main"> <BR> <formenctype= "Multipart/form-data"> <Divclass= "Form-group"> <!--Initializing plug-ins - <inputID= "File-1"type= "File"Multiple Class= "File"data-overwrite-initial= "false"Data-min-file-count= "2"name= "Images"> </Div> </form> </Div> </Body> <Script> //initializes the Filleinput control for the first time functioninitfileinput (Ctrlname, uploadurl) {varControl= $('#'+ctrlname); Control.fileinput ({language:'ZH', //Set LanguageUploadurl:uploadurl,//Address to uploadallowedfileextensions:['jpg','PNG'], //received file suffixShowupload:true, //whether to display the upload buttonshowcaption:false, //whether to show titleMaxFileSize: +, //picture Maximum size KB is 0 No limitMaxfilesnum:3, //upload images up tooverwriteinitial:false,//do not overwrite uploaded picturesBrowseclass:"btn Btn-info", //button Styledropzoneenabled:true,//whether to display the drag areaPreviewfileicon:"<i class= ' Glyphicon glyphicon-king ' ></i>", Msgfilestoomany:"Select the number of uploaded files ({n}) exceeding the maximum allowable value {m}! ", }); } //initializes the Fileinput control, first initialization (control ID, upload address)Initfileinput ("file-1", "uploadimg"); //Monitoring Events $("#file-1"). On ("fileuploaded", function(event, data, Previewid, index) {//Upload Addressconsole.log (data); }); </Script></HTML>
Background code:
/** BOOTST Multi-image upload*/ Public functionFileinput () {return $this-fetch (); } Public functionuploadimg () {//Var_dump ($_files); Get form upload file $file= Request ()file(' Images '); //move to the Framework app root directory under the/public/uploads/img directory $info=$file->move (Root_path. ' Public '. Ds. ' Uploads/img '); if($info){ //Upload information after successful upload $data[' response '] =$info-Getsavename (); returnJson$data); //image upload Successful, the following can be done on the database//... }Else{ //upload failed get error message Echo $file-GetError (); } }
Bootstrap+php to achieve multi-image upload