Php+ajax upload Image instance code without refresh, _php tutorial

Source: Internet
Author: User

Php+ajax No refresh upload image instance code,


This article shared the PHP with Ajax implementation of no-refresh upload images of the instance code, share to everyone, I hope you can and small together learn to learn, common progress.

1. Introduction of files

 
  
 
  
 
  

2.html part

                      
 
          "height=" 120px ">        
 
                                    Add a picture                         

3. Add a form to FileUpload

/* Image upload */  $ (". FileUpload"). Wrap (""); function processing

4.ajax File Upload

JQuery (function ($) {   $ (". FileUpload"). Change (function () {///Select File     if (' = = = $ (this). Val ()) return;    var upimg = $ (this). Parent (). Parent (). parent ();    var showimg = Upimg.find ('. showimg ');    var btn = Upimg.find ('. btn span ');    var imgsrc = Upimg.find ('. imgsrc ');    $ (this). Parent (). Ajaxsubmit ({       //datatype: ' json ',//Data format JSON       beforesend:function () {//Start uploading         Showimg.empty (); Empty the displayed picture         imgsrc.val ("");        Btn.html ("Upload ..."); The upload button displays in upload       },       uploadprogress:function (event, Position, total, PercentComplete) {       },       success: function (data) {//Success         //Get JSON data returned in background, display file name, size, and delete button         var img = data;        Display the uploaded picture         imgsrc.val ("");        Imgsrc.val (IMG);        Showimg.html ("");         Btn.html ("Upload success"); Upload button Restore       },       error:function (XHR) {//upload failed         btn.html ("Upload failed");       }     );   

5. Processing in the background

Public Function Uploadpicaction () {//Picture upload and display    $data = "";    $SRC = $this->uploadfiles2 ($imgpath = "/upload/book", $filesname = "pic");          Isset ($src [0][' src ']) && $src [0][' src ']? $data = $this->concaturl ($src [0][' src ']): null;    echo $data;   }

6. Give the returned data to the front end for some processing.

It is then submitted to the background database.

I hope this article will help you learn PHP programming.

http://www.bkjia.com/PHPjc/1072545.html www.bkjia.com true http://www.bkjia.com/PHPjc/1072545.html techarticle Php+ajax No refresh upload Image instance code, this article shared the PHP with Ajax implementation of no refresh upload image instance code, share to everyone, I hope you can and small together learn to learn, ...

  • 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.