PHP+AJAX+JS implementation of multi-image upload Ajax php post jquery Ajax PHP Ajax

Source: Internet
Author: User
Tags learn php learn php programming
This example in the WAP station project needs to do an AJAX multi-image upload, combined with JS plugin made a, for your reference, the specific content as follows

/* Ajax Upload image */var num = 0; Click Delete Picture function OnDelete (num) {if ($ ("#" +num). attr (' src ')! = "__public__/home/images/jiazai.gif" && $ ("#" +      num). attr (' src ')! = "") {if (Confirm ("confirm Delete")) {$ ("#a" +num). Remove ();               }else{//}}}$ (function () {$ ("#file0"). Bind ("Change", function () {clickupload (num);     });               function Clickupload (num) {var imgobject = document.getElementById (' File0 ');//File Object $ ("#yulan"). Append (""); $ ("#yulan"). Append ("
 
  Delete"); var getimagesrc = GetFullPath (Imgobject);       Local Path//instanced Image object var pos = Getimagesrc.lastindexof ("."); var LastName = getimagesrc.substring (pos, getimagesrc.length)//Picture suffix if (lastname!= ". jpg" && lastname!= ". PN          G "&& 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) {//Gets 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.i          TEM (0). Getasdataurl ();        } return obj.value;      } return obj.value; }} functiOn Ajaxfileupload (num) {$.ajaxfileupload ({url: ' http://xxxx/updateImg '),//server-side request address for file upload Secureuri:false,//Whether a security protocol is required, generally set to false fileelementid: ' FILE0 ',//File upload domain ID dataType: ' JSON ',//return             The 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 ("Image upload failed");       }                      },   Error:function (data,e)//server response failed processing function {alert (e); }        }      )    }});
 

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

The above describes the PHP+AJAX+JS implementation of multi-image upload, including the ajax,php aspects of the content, I hope that the PHP tutorial interested friends to 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.