这篇文章主要为大家详细介绍了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"}
<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 的反射详解及实例分析
php实现 flush无效,iis7下php实时输出的方法
php flush 函数的使用注意事项
以上就是php mvc框架skymvc支持多文件上传实现方法的详细内容。