PHP skymvc架構如何?多檔案上傳

來源:互聯網
上載者:User
本文主要為大家詳細介紹了php mvc架構skymvc檔案上傳實現代碼,支援多檔案上傳操作,感興趣的小夥伴們可以參考一下。希望對大家有所協助。

本文執行個體為大家分享了skymvc實現檔案上傳的具體代碼,供大家參考,具體內容如下

1.代碼upload.ctrl.php

<?phpclass 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"}<p class="main-body box960"> <form method="post" action="/index.php?m=upload&a=upload" enctype="multipart/form-data"> <p class="row">  <p class="btn-upload">   <i class="iconfont icon-upload"></i>   上傳檔案   <p class="btn-upload-file">    <input type="file" id="upimg" name="upimg" multiple>    </p>  </p> </p> <p style="height:10px;"></p> <p class="row"> <input type="submit" class="btn" value="上傳"> </p> </form> <h3>上傳結果</h3> <p class="result" id="result"></p></p>{include file="footer.html"}<style> .result{border:1px solid #ccc; padding:5px;} .result p{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('<p class="e">error:'+data.err+'</p>');   }else{    $("#result").append('<p class="s">success:'+data.filename+'</p>');   }  }); });</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 skymvc 一款簡單的php架構

skymvc網站測試之頁面測試,爬行所有頁面

skymvc網站測試之mysql資料產生

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.