您好,登錄后才能下訂單哦!
這篇文章主要介紹PHP MVC框架skymvc如何實(shí)現(xiàn)支持多文件上傳,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
具體內(nèi)容如下
1.代碼upload.ctrl.php
<?php class uploadControl extends skymvc{ public function __construct(){ parent::__construct(); } public function onDefault(){ $this->smarty->display("upload/default.html"); } public function onUpload(){ $this->loadClass("upload"); //上傳的文件目錄 $this->upload->uploaddir="attach/my/"; //允許上傳的文件大小 $this->upload->maxsize=4194304000; //是否上傳圖片 $this->upload->upimg=true; //設(shè)置允許上傳的文件類型 $this->upload->sysallowtype=array('gif','jpg','bmp','png','jpeg','txt','mpeg','avi','rm','rmvb','wmv','flv','mp3','wav','wma','swf','doc','pdf','zip','tar','svg'); $this->upload->allowtype=$this->upload->sysallowtype; //根據(jù)Id存儲(chǔ) $this->upload->iddir=0; $data=$this->upload->uploadfile("upimg"); //print_r($data); echo json_encode($data); } } ?>
2.代碼upload.html
<!doctype html> <html> {include file="head.html"} <body> {include file="header.html"} <div class="main-body box960"> <form method="post" action="/index.php?m=upload&a=upload" enctype="multipart/form-data"> <div class="row"> <div class="btn-upload"> <i class="iconfont icon-upload"></i> 上傳文件 <div class="btn-upload-file"> <input type="file" id="upimg" name="upimg" multiple> </div> </div> </div> <div ></div> <div class="row"> <input type="submit" class="btn" value="上傳"> </div> </form> <h4>上傳結(jié)果</h4> <div class="result" id="result"></div> </div> {include file="footer.html"} <style> .result{border:1px solid #ccc; padding:5px;} .result div{line-height:24px;} .result .e{color:#D58384;} .result .s{color:#59A42A;} </style> <script src="/static/js/skyupload.js"></script> <script> $(document).on("change","#upimg",function(data){ skyUpload("upimg","/index.php?m=upload&a=upload&ajax=1",function(e){ var data=eval("("+e.target.responseText+")"); if(data.err){ $("#result").append('<div class="e">error:'+data.err+'</div>'); }else{ $("#result").append('<div class="s">success:'+data.filename+'</div>'); } }); }); </script> </body> </html>
3.PHP代碼
function skyUpload(upid,url,success,error,uploadProgress) { var vFD = new FormData(); var f= document.getElementById(upid).files; $("#"+upid+"loading").show(); for(var i=0;i<f.length;i++){ vFD.append('upimg', document.getElementById(upid).files[i]); var oXHR = new XMLHttpRequest(); oXHR.addEventListener('load', success, false); oXHR.addEventListener('error', error, false); if(uploadProgress!=undefined){ oXHR.upload.addEventListener("progress", uploadProgress, false); } oXHR.open('POST',url); oXHR.send(vFD); } } /* function uploadFinish(e){ var data=eval("("+e.target.responseText+")"); $("#uploading").hide() if(data.error != '') { skyToast(data.msg); }else { $("#imgShow").html("<img src='/"+data.imgurl+".100x100.jpg' width='100'>"); $("#imgurl").val(data.imgurl); } } function uploadError(e) { // upload error skyToast("上傳出錯(cuò)了"); } */
以上是“PHP MVC框架skymvc如何實(shí)現(xiàn)支持多文件上傳”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。