PHP MVC framework skymvc supports multiple file upload implementation methods

墨辰丷
Release: 2023-03-29 12:00:02
Original
9981 people have browsed it

This article mainly introduces the PHP mvc framework skymvc file upload implementation code in detail, which supports multiple file upload operations. Interested friends can refer to it

The specific content is as follows

1.Code 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(&#39;gif&#39;,&#39;jpg&#39;,&#39;bmp&#39;,&#39;png&#39;,&#39;jpeg&#39;,&#39;txt&#39;,&#39;mpeg&#39;,&#39;avi&#39;,&#39;rm&#39;,&#39;rmvb&#39;,&#39;wmv&#39;,&#39;flv&#39;,&#39;mp3&#39;,&#39;wav&#39;,&#39;wma&#39;,&#39;swf&#39;,&#39;doc&#39;,&#39;pdf&#39;,&#39;zip&#39;,&#39;tar&#39;,&#39;svg&#39;);
  $this->upload->allowtype=$this->upload->sysallowtype;
  //根据Id存储
  $this->upload->iddir=0;
  $data=$this->upload->uploadfile("upimg");
  //print_r($data);
  echo json_encode($data); 
   
 }
  
  
  
}
 
?>
Copy after login

2.Code 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(&#39;<p class="e">error:&#39;+data.err+&#39;</p>&#39;);
   }else{
    $("#result").append(&#39;<p class="s">success:&#39;+data.filename+&#39;</p>&#39;);
   }
  });
 });
</script>
</body>
</html>
Copy after login

3.PHP code

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(&#39;upimg&#39;, document.getElementById(upid).files[i]);
   var oXHR = new XMLHttpRequest();  
   oXHR.addEventListener(&#39;load&#39;, success, false);
   oXHR.addEventListener(&#39;error&#39;, error, false);
   if(uploadProgress!=undefined){
    oXHR.upload.addEventListener("progress", uploadProgress, false);
   }
   oXHR.open(&#39;POST&#39;,url);
   oXHR.send(vFD);
  
   }
}
 
/*
function uploadFinish(e){
  var data=eval("("+e.target.responseText+")");
  $("#uploading").hide()
  if(data.error != &#39;&#39;)
  {
   skyToast(data.msg);
  }else
  {
   $("#imgShow").html("<img src=&#39;/"+data.imgurl+".100x100.jpg&#39; width=&#39;100&#39;>");
   $("#imgurl").val(data.imgurl);
   }
}
  
function uploadError(e) { // upload error
  skyToast("上传出错了");
}
*/
Copy after login

Summary: The above is the entire content of this article , I hope it can be helpful to everyone’s study.

Related recommendations:

php Detailed reflection and example analysis

php Implementing flush is invalid, phpmethod of real-time output under IIS7

Notes on using PHP flush function

The above is the detailed content of PHP MVC framework skymvc supports multiple file upload implementation methods. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!