PHP MVC框架skymvc支持多文件上傳
本文實(shí)例為大家分享了skymvc實(shí)現(xiàn)文件上傳的具體代碼,供大家參考,具體內(nèi)容如下
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;
//設(shè)置允許上傳的文件類型
$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;
//根據(jù)Id存儲(chǔ)
$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>上傳結(jié)果</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("上傳出錯(cuò)了");
}
*/
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)php程序設(shè)計(jì)有所幫助。
- php打造屬于自己的MVC框架
- PHP的MVC模式實(shí)現(xiàn)原理分析(一相簡(jiǎn)單的MVC框架范例)
- php實(shí)現(xiàn)最簡(jiǎn)單的MVC框架實(shí)例教程
- 基于PHP Web開發(fā)MVC框架的Smarty使用說明
- php實(shí)現(xiàn)簡(jiǎn)單的MVC框架實(shí)例
- 搭建自己的PHP MVC框架詳解
- PHP簡(jiǎn)單的MVC框架實(shí)現(xiàn)方法
- PHP仿tp實(shí)現(xiàn)mvc框架基本設(shè)計(jì)思路與實(shí)現(xiàn)方法分析
- PHP從零開始打造自己的MVC框架之入口文件實(shí)現(xiàn)方法詳解
相關(guān)文章
ThinkPHP使用PHPExcel實(shí)現(xiàn)Excel數(shù)據(jù)導(dǎo)入導(dǎo)出完整實(shí)例
這篇文章主要介紹了ThinkPHP使用PHPExcel實(shí)現(xiàn)Excel數(shù)據(jù)導(dǎo)入導(dǎo)出,非常實(shí)用的功能,需要的朋友可以參考下2014-07-07
PHP實(shí)現(xiàn)PDF轉(zhuǎn)圖片的方法詳解
這篇文章主要給大家介紹了關(guān)于PHP將PDF轉(zhuǎn)圖片的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-12-12
PHP使用CURL實(shí)現(xiàn)下載文件功能示例
這篇文章主要介紹了PHP使用CURL實(shí)現(xiàn)下載文件功能,結(jié)合具體實(shí)例形式分析了php基于curl的文件下載實(shí)現(xiàn)技巧,代碼注釋有詳細(xì)的功能說明,并附帶了curl參數(shù)的功能講解,需要的朋友可以參考下2019-06-06
php htmlspecialchars()與shtmlspecialchars()函數(shù)的深入分析
本篇文章是對(duì)php中的htmlspecialchars()與shtmlspecialchars() 函數(shù)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06

