您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍PHP MVC框架skymvc如何实现支持多文件上传,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
具体内容如下
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; //设置允许上传的文件类型 $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; //根据Id存储 $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>上传结果</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("上传出错了"); } */
以上是“PHP MVC框架skymvc如何实现支持多文件上传”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。