PHP + JavaScript allows you to upload images without refreshing, while javascript uploads images.

Source: Internet
Author: User

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!

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.