当前位置:Gxlcms > PHP教程 > JQ插件ajaxFileUpload、php实现图片,数据同时上传,_PHP教程

JQ插件ajaxFileUpload、php实现图片,数据同时上传,_PHP教程

时间:2021-07-01 10:21:17 帮助过:4人阅读

JQ插件ajaxFileUpload、php实现图片,数据同时上传,


代码结构如下:

1、HTML代码,没必要解释了。

 1https://www.gxlcms.com/ DOCTYPE htmlhttps://www.gxlcms.com/>https://www.gxlcms.com/
 2https://www.gxlcms.com/ htmlhttps://www.gxlcms.com/>https://www.gxlcms.com/
 3https://www.gxlcms.com/     headhttps://www.gxlcms.com/>https://www.gxlcms.com/
 4https://www.gxlcms.com/         meta https://www.gxlcms.com/charsethttps://www.gxlcms.com/="UTF-8"https://www.gxlcms.com/>https://www.gxlcms.com/
 5https://www.gxlcms.com/         titlehttps://www.gxlcms.com/>https://www.gxlcms.com/文件上传titlehttps://www.gxlcms.com/>https://www.gxlcms.com/
 6https://www.gxlcms.com/         script https://www.gxlcms.com/srchttps://www.gxlcms.com/="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"https://www.gxlcms.com/>scripthttps://www.gxlcms.com/>https://www.gxlcms.com/
 7https://www.gxlcms.com/         script https://www.gxlcms.com/srchttps://www.gxlcms.com/="uploads/ajaxFileUpload.js"https://www.gxlcms.com/ typehttps://www.gxlcms.com/="text/javascript"https://www.gxlcms.com/ charsethttps://www.gxlcms.com/="utf-8"https://www.gxlcms.com/>scripthttps://www.gxlcms.com/>https://www.gxlcms.com/
 8https://www.gxlcms.com/         script https://www.gxlcms.com/typehttps://www.gxlcms.com/="text/javascript"https://www.gxlcms.com/>https://www.gxlcms.com/
 9https://www.gxlcms.com/             $(https://www.gxlcms.com/functionhttps://www.gxlcms.com/(){
https://www.gxlcms.com/10https://www.gxlcms.com/                 $(https://www.gxlcms.com/'https://www.gxlcms.com/#tihttps://www.gxlcms.com/'https://www.gxlcms.com/).click(https://www.gxlcms.com/functionhttps://www.gxlcms.com/(){
https://www.gxlcms.com/11https://www.gxlcms.com/                     varhttps://www.gxlcms.com/ data https://www.gxlcms.com/=https://www.gxlcms.com/ { name: https://www.gxlcms.com/'https://www.gxlcms.com/my namehttps://www.gxlcms.com/'https://www.gxlcms.com/, description: https://www.gxlcms.com/'https://www.gxlcms.com/short descriptionhttps://www.gxlcms.com/'https://www.gxlcms.com/ } 
https://www.gxlcms.com/12https://www.gxlcms.com/                     $.ajaxFileUpload({
https://www.gxlcms.com/13https://www.gxlcms.com/                         url: https://www.gxlcms.com/'https://www.gxlcms.com/up.phphttps://www.gxlcms.com/'https://www.gxlcms.com/,
https://www.gxlcms.com/14https://www.gxlcms.com/                         secureuri: https://www.gxlcms.com/falsehttps://www.gxlcms.com/,
https://www.gxlcms.com/15https://www.gxlcms.com/                         data: data,
https://www.gxlcms.com/16https://www.gxlcms.com/                         fileElementId: https://www.gxlcms.com/'https://www.gxlcms.com/upfhttps://www.gxlcms.com/'https://www.gxlcms.com/,
https://www.gxlcms.com/17https://www.gxlcms.com/                         dataType: https://www.gxlcms.com/'https://www.gxlcms.com/jsonhttps://www.gxlcms.com/'https://www.gxlcms.com/,
https://www.gxlcms.com/18https://www.gxlcms.com/                         success: https://www.gxlcms.com/functionhttps://www.gxlcms.com/ (data) {
https://www.gxlcms.com/19https://www.gxlcms.com/                            //https://www.gxlcms.com/ var datejson=eval(data);https://www.gxlcms.com/
20https://www.gxlcms.com/                              //https://www.gxlcms.com/console.log(data[0].path_name)https://www.gxlcms.com/
21https://www.gxlcms.com/                          $(https://www.gxlcms.com/'https://www.gxlcms.com/#imhttps://www.gxlcms.com/'https://www.gxlcms.com/).append(https://www.gxlcms.com/'https://www.gxlcms.com/https://www.gxlcms.com/'https://www.gxlcms.com/)    
https://www.gxlcms.com/22https://www.gxlcms.com/                              //https://www.gxlcms.com/console.log('')https://www.gxlcms.com/
23https://www.gxlcms.com/                         },
https://www.gxlcms.com/24https://www.gxlcms.com/                         error: https://www.gxlcms.com/functionhttps://www.gxlcms.com/ (data) {
https://www.gxlcms.com/25https://www.gxlcms.com/                               console.log(data)
https://www.gxlcms.com/26https://www.gxlcms.com/                         }
https://www.gxlcms.com/27https://www.gxlcms.com/                     });
https://www.gxlcms.com/28https://www.gxlcms.com/ 
29https://www.gxlcms.com/                 })
https://www.gxlcms.com/30https://www.gxlcms.com/                 
31https://www.gxlcms.com/             })
https://www.gxlcms.com/32https://www.gxlcms.com/         scripthttps://www.gxlcms.com/>https://www.gxlcms.com/
33https://www.gxlcms.com/     headhttps://www.gxlcms.com/>https://www.gxlcms.com/
34https://www.gxlcms.com/     bodyhttps://www.gxlcms.com/>https://www.gxlcms.com/
35https://www.gxlcms.com/     https://www.gxlcms.com/
37https://www.gxlcms.com/         input  https://www.gxlcms.com/typehttps://www.gxlcms.com/="file"https://www.gxlcms.com/ namehttps://www.gxlcms.com/="upfm"https://www.gxlcms.com/ idhttps://www.gxlcms.com/="upf"https://www.gxlcms.com/ valuehttps://www.gxlcms.com/=""https://www.gxlcms.com/ />https://www.gxlcms.com/
38https://www.gxlcms.com/         input https://www.gxlcms.com/idhttps://www.gxlcms.com/='ti' https://www.gxlcms.com/typehttps://www.gxlcms.com/="button"https://www.gxlcms.com/ valuehttps://www.gxlcms.com/="提交"https://www.gxlcms.com//>https://www.gxlcms.com/
39https://www.gxlcms.com/ 
40https://www.gxlcms.com/         div https://www.gxlcms.com/idhttps://www.gxlcms.com/="im"https://www.gxlcms.com/>https://www.gxlcms.com/
41https://www.gxlcms.com/             
42https://www.gxlcms.com/         divhttps://www.gxlcms.com/>https://www.gxlcms.com/
43https://www.gxlcms.com/         
44https://www.gxlcms.com/     bodyhttps://www.gxlcms.com/>https://www.gxlcms.com/
45https://www.gxlcms.com/ 
46https://www.gxlcms.com/ htmlhttps://www.gxlcms.com/>https://www.gxlcms.com/

2、关于ajaxFileUpload插件,在下面代码中如果你使用的是JQ1.9以上请复制1-12到你的ajaxFileUpload代码中,JQ在很早就废弃了handleError方法。注释关于代码的解释很清楚。

  1https://www.gxlcms.com/ jQuery.extend({
https://www.gxlcms.com/  2https://www.gxlcms.com/     handleError: functionhttps://www.gxlcms.com/( s, xhr, status, e )         {
https://www.gxlcms.com/  3https://www.gxlcms.com/         
  4https://www.gxlcms.com/                 ifhttps://www.gxlcms.com/ ( s.error ) {
https://www.gxlcms.com/  5https://www.gxlcms.com/                     s.error.call( s.context || s, xhr, status, e );
https://www.gxlcms.com/  6https://www.gxlcms.com/                 }
https://www.gxlcms.com/  7https://www.gxlcms.com/ 
  8https://www.gxlcms.com/                 
  9https://www.gxlcms.com/                 ifhttps://www.gxlcms.com/ ( s.global ) {
https://www.gxlcms.com/ 10https://www.gxlcms.com/                     (s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] );
https://www.gxlcms.com/ 11https://www.gxlcms.com/                 }
https://www.gxlcms.com/ 12https://www.gxlcms.com/    },
https://www.gxlcms.com/ 13https://www.gxlcms.com/     createUploadIframe: functionhttps://www.gxlcms.com/ (id, uri) {//https://www.gxlcms.com/id为当前系统时间字符串,uri是外部传入的json对象的一个参数https://www.gxlcms.com/
 14https://www.gxlcms.com/         //https://www.gxlcms.com/create framehttps://www.gxlcms.com/
 15https://www.gxlcms.com/         varhttps://www.gxlcms.com/ frameId = 'jUploadFrame' + id; //https://www.gxlcms.com/给iframe添加一个独一无二的idhttps://www.gxlcms.com/
 16https://www.gxlcms.com/         varhttps://www.gxlcms.com/ iframeHtml = '