国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

移動端HTML5實現文件上傳

2020-03-24 17:24:28
字體:
來源:轉載
供稿:網友
PC端上傳文件多半用插件,引入flash都沒關系,但是移動端要是還用各種冗余的插件估計得被噴死,項目里面需要做圖片上傳的功能,既然H5已經有相關的接口且兼容良好,當然優先考慮用H5來實現。用的技術主要是:ajaxFileReaderFormDataHTML結構:XML/HTML Code復制內容到剪貼板
$.extend($.fn,{ fileUpload:function(opts){ this.each(function(){ var$self=$(this); vardoms={ fileToUpload :$self.find( .fileToUpload ), thumb :$self.find( .thumb ), progress :$self.find( .upload-progress ) }; varfuns={ //選擇文件,獲取文件大小,也可以在這里獲取html' target='_blank'>文件格式,限制用戶上傳非要求格式的文件 fileSelected :function(){ varfiles=(doms.fileToUpload)[0].files; varcount=files.length; for(varindex=0;index count;index++){ varfile=files[index]; varfileSize=0; if(file.size 1024*1024) fileSize=(Math.round(file.size*100/(1024*1024))/100).toString()+'MB'; else fileSize=(Math.round(file.size*100/1024)/100).toString()+'KB'; } funs.uploadFile(); }, //異步上傳文件 uploadFile:function(){ varfd=newFormData();//創建表單數據對象 varfiles=(doms.fileToUpload)[0].files; varcount=files.length; for(varindex=0;index count;index++){ varfile=files[index]; fd.append(opts.file,file);//將文件添加到表單數據中 funs.previewImage(file);//上傳前預覽圖片,也可以通過其他方法預覽txt } varxhr=newXMLHttpRequest(); xhr.upload.addEventListener( progress ,funs.uploadProgress,false);//監聽上傳進度 xhr.addEventListener( load ,funs.uploadComplete,false); xhr.addEventListener( error ,opts.uploadFailed,false); xhr.open( POST ,opts.url); xhr.send(fd); }, //文件預覽 previewImage:function(file){ vargallery=doms.thumb; varimg=document.createElement( img ); img.file=file; doms.thumb.html(img); //使用FileReader方法顯示圖片內容 varreader=newFileReader(); reader.onload=(function(aImg){ returnfunction(e){ aImg.src=e.target.result; }; })(img); reader.readAsDataURL(file); }, uploadProgress:function(evt){ if(evt.lengthComputable){ varpercentComplete=Math.round(evt.loaded*100/evt.total); doms.progress.html(percentComplete.toString()+'%'); } }, uploadComplete :function(evt){ alert(evt.target.responseText) } }; doms.fileToUpload.on( change ,function(){ doms.progress.find( span ).width( 0 ); funs.fileSelected(); }); }); } }); })(Zepto);
writeLog($_FILES); move_uploaded_file($_FILES['myFile']['tmp_name'], uploads/ .$_FILES['myFile']['name']); echo'successful'; } functionwriteLog($log){ if(is_array($log)||is_object($log)){ $log=json_encode($log); } $log=$log. /r/n ; file_put_contents('log.log',$log,FILE_APPEND); } ?
以上就是本文的全部內容,希望對大家的學習有所幫助。原文:http://www.cnblogs.com/hutuzhu/p/5254532.htmlhtml教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 方城县| 福清市| 武夷山市| 渝中区| 安平县| 酒泉市| 紫云| 美姑县| 金秀| 苍梧县| 隆昌县| 施秉县| 昭苏县| 成武县| 彭水| 斗六市| 凤城市| 穆棱市| 定兴县| 五华县| 庄河市| 专栏| 中方县| 方正县| 怀集县| 彭州市| 大港区| 长岭县| 弋阳县| 册亨县| 图木舒克市| 南平市| 渝中区| 辽中县| 天峻县| 建始县| 东辽县| 张掖市| 广州市| 日土县| 浠水县|