PHP MVC框架skymvc支持多文件上传

yipeiwu_com4年前PHP代码库

本文实例为大家分享了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 style="height:10px;"></div>
 <div class="row">
 <input type="submit" class="btn" value="上传">
 </div>
 </form>
 <h3>上传结果</h3>
 <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程序设计有所帮助。

相关文章

队列在编程中的实际应用(php)

队列在编程中的实际应用(php)

一:队列的概念、数据结构 队列(Queue)是运算受到限制的一种线性表。只允许在表的一端进行插入,而在另一端进行删除元素的线性表。队尾(rear)是允许插入的一端。队头(front)是允...

php中$_GET与$_POST过滤sql注入的方法

本文实例讲述了php中$_GET与$_POST过滤sql注入的方法,分享给大家供大家参考。具体分析如下: 此函数只能过滤一些敏感的sql命令了,像id=1这种大家还是需要自己简单过滤了。...

php utf-8转unicode的函数第1/2页

UTF编码 UTF-8就是以8位为单元对UCS进行编码。从UCS-2到UTF-8的编码方式如下: UCS-2编码(16进制) UTF-8 字节流(二进制) 0000 - 007F 0xx...

PHP简单获取上月、本月、近15天、近30天的方法示例

本文实例讲述了PHP简单获取上月、本月、近15天、近30天方法。分享给大家供大家参考,具体如下: /** * 获取统计时间 * @param $type * 1 上月 * 2...

php基于登陆时间判断实现一天多次登录只积分一次功能示例

本文实例讲述了php基于登陆时间判断实现一天多次登录只积分一次功能。分享给大家供大家参考,具体如下: 在网上找了很多的案例,感觉都差不多,有的还比较的繁琐,就自己尝试了一下,如何实现这个...