Jquery + html + php implement Ajax without refreshing File Upload

Source: Internet
Author: User

You can use php + jquery + html to upload ajax files without any need. Here we mainly use a jquery plug-in (also known as the ajax File Upload Component) ajaxfileupload. This plug-in actually adopts the iframe File Upload principle, that is, a dynamic IFRAME form is embedded in the page, and then the IFRAME uses the native POST form to submit data. The following is an example.

Jquery + HTML code:

<Html> 

Php code (that is, the doajaxfileupload. php file in the above instance ):

<? Php $ upFilePath = ". /uploads "; $ f = @ move_uploaded_file ($ _ FILES ['img '] ['tmp _ name'], $ upFilePath); if ($ f = FALSE) {echo json_encode (array ('code' => 1, 'message' => 'upload failed', 'file _ url' => $ upFilePath. $ _ FILES ['img '] ['tmp _ name']);} else {echo json_encode (array ('code' => 0, 'message' => 'uploaded successfully', 'file _ url' => $ upFilePath. $ _ FILES ['img '] ['tmp _ name']);}

The above examples are rough, and the specific errors and detailed handling steps are still to be improved by friends based on their own circumstances. The following figure shows the information about the ajaxfileupload ajax node that does not need to be updated:

This component home page (home page has this component and instances): http://www.phpletter.com/Demo/AjaxFileUpload-Demo/

Articles you may be interested in
  • PHP analyzes the file header information to determine the type of the uploaded file
  • Php uses the ZipArchive function to compress and decompress files.
  • Php clears (deletes) the files in the specified directory, and does not delete the directory folder.
  • Php uses header () to download files. The downloaded files prompt that they are damaged and cannot be opened.
  • Php File Upload process and summary
  • PHP File Upload configuration tutorial
  • Reasons why PHP adds a backslash before the quotation mark and how PHP removes the backslash, there are three ways to disable the php magic quotation mark
  • Php's function of limiting file download speeds

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.