Php+ajax+js to realize multi-graph upload _php instance

Source: Internet
Author: User

This article example in the WAP station project needs to do an AJAX multiple image upload, combined with JS plug-in to do a, for everyone's reference, the specific content as follows

/* Ajax Upload Picture * * var num = 0; Click Delete Picture function OnDelete (num) {if ($ ("#" +num). attr (' src ')!= "__public__/home/images/jiazai.gif" && $ ("#" +
      num). attr (' src ')!= "") {if (Confirm ("Confirm deletion")) {$ ("#a" +num). Remove (); }else{//}} $ (function () {$ ("#file0"). Bind ("Change", function () {Clickupload (nu
           
    m); 
    }); function Clickupload (num) {var imgobject = document.getElementById (' File0 ');//File Object $ ("#yulan"). Append ("&l T;a id= ' A "+num+" ' onclick= ' OnDelete ("+num+") ' href= ' javascript:; '
        
       > </a> '); $ ("#yulan"). Append ("<li id= ' a" +num+ "' > Delete </a></li> '); var getimagesrc = GetFullPath (Imgobject); Local path//materialized Image object var pos = GetImageSrc.lastindexof ("."); var LastName = getimagesrc.substring (pos, getimagesrc.length)//Picture suffix if (lastname!= ". jpg" && lastname!= ".
          PNG "&& lastname!=". jpeg "&& lastname!= '. gif ') {$ (" #a "+num). Remove ();
       Alert ("Please select a picture");
         }else{ajaxfileupload (num);
          $ ("#file0"). Unbind ("Change"). Bind ("Change", function () {clickupload (num);
       });
    } num++;  } function GetFullPath (obj) {//Get the full path of the picture if (obj) {if (Window.navigator.userAgent.indexOf ("MSIE")
          >= 1) {obj.select ();
        Return Document.selection.createRange (). text; }else if (window.navigator.userAgent.indexOf ("Firefox") >= 1) {if (obj.files) {return obj.files
          . Item (0). Getasdataurl ();
        return obj.value;
      return obj.value;
       }} function Ajaxfileupload (num) {$.ajaxfileupload ({   URL: ' http://xxxx/updateImg ',//For file Upload server-side request address secureuri:false,//Whether security protocol is required, generally set to false fileelement
          ID: ' FILE0 ',//File upload domain ID dataType: ' JSON ',//return value type is generally set to JSON success:function (data)//Server Success Response handler function 
            {var jsontext = data;
            Console.log (Jsontext);
                if (jsontext[' status ']==1) {if (jsontext[' info ']!= ") {Console.log (jsontext[' info ']);
   
                 $ ("#" +num). attr ("src", "__public__//admin/upload/" +jsontext[' info '));
   
                var images = $ ("#img"). Val ();
                if (images!= "") {$ ("#img"). Val (images+ ", +jsontext[' info '));
                }else{$ ("#img"). Val (images+ "+jsontext[' info '));
              }}else{$ ("#a" +num). Remove ();  
            Alert ("Picture upload failed");
  }}, Error:function (data,e)//server response failed handler function        {alert (e); }
        }
      )
    }
});

The above is the entire content of this article, I hope that you learn PHP program help.

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.