PHP + JavaScript allows you to upload images without refreshing, while javascript uploads images.
Html file code
<! -- Ajax File Upload start --> <script type = "text/javascript" src = "/imageupload/jquery-1.10.2.min.js"> </script> <script type = "text/javascript" src = "/imageupload/layer. js "> </script> <script type =" text/javascript "src ="/imageupload/ajaxupload. js "> </script> <! -- Ajax File Upload ends --> <! -- Start the upload File button list --> <input id = "requesturl" type = "hidden" value = "{: U ('admin/upload/uploadfile ')} "/> <input id =" ajaxuploadfile "type =" file "onchange =" filechange () "/> <input id =" filepathurl "type =" hidden "value =" "/> <input type =" button "value =" first "pathurl = ". /Uploads/admin/trailer/"class =" uploadclass "/> <input type =" button "value =" second "pathurl = ". /Uploads/admin/fdfdfd/"class =" uploadclass "/> <input type =" bu Tton "value =" third "pathurl ="./Uploads/admin/cdcdfd/"class =" uploadclass "/> <! -- The Upload File button list ends -->
PHP file code
/*** File upload Method */public function uploadfile () {// single file Upload $ upload = new \ Think \ Upload (); // instantiate the upload class $ upload-> maxSize = 100000000; // set the attachment upload size $ upload-> exts = array ('jpg ', 'gif', 'png ', 'jpeg '); // sets the attachment upload type $ url =$ _ POST ['filepathurl']; if (! File_exists ($ url) {mkdir ($ url, 0777, true) ;}$ upload-> rootPath = $ url; // set the root directory for uploading attachments // upload a single file $ info = $ upload-> uploadOne ($ _ FILES ['postfilename']); if (! $ Info) {echo json_encode (array ('bool '=> false, 'error' => $ upload-> getError ()));} else {$ path = $ info ['savepath']. $ info ['savename']; echo json_encode (array ('bool '=> true, 'path' => $ path ));}}
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!