Ajax allows you to upload files without refreshing the new upload function.

Source: Internet
Author: User

Ajax allows you to upload files without refreshing the new upload function.

This article provides examples to share with you the specific code for implementing the File Upload without refreshing ajax function for your reference. The specific content is as follows:

The Code is as follows:

<! Doctype html> 

Backend php code post_file.php

<? Phpheader ('content-type: text/html; charset = "UTF-8" '); $ upload_dir = 'uploads /'; if (strtolower ($ _ SERVER ['request _ method'])! = 'Post') {exit_status (array ('code' => 1, 'msg '=> 'incorrect submission method');} if (array_key_exists ('file ', $ _ FILES) & $ _ FILES ['file'] ['error'] = 0) {$ pic = $ _ FILES ['file']; if (move_uploaded_file ($ pic ['tmp _ name'], $ upload_dir. $ pic ['name']) {exit_status (array ('code' => 0, 'msg '=> 'uploaded successfully', 'url' => $ upload_dir. $ pic ['name']);} echo $ _ FILES ['file'] ['error']; exit_status (array ('code' => 1, 'msg '=>' some errors occur '); function exit_status ($ s Tr) {echo json_encode ($ str); exit ;}?>

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

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.