三款php多文件上传实例代码(1/3)_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了三款php多文件上传实例代码(1/3)_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3113字,纯文字阅读大概需要5分钟。
内容图文
![三款php多文件上传实例代码(1/3)_PHP教程](/upload/InfoBanner/zyjiaocheng/173/0889df2d208a4be5a01d73d28974fef5.jpg)
三款php教程多文件上传实例代码
在php开发应用中经常会碰到文件上传这个需,有时也会碰到要多文件上传,下面我们就来看看我提供的三款php多文件上传实例代码,好了费话不说多了来看看这些多文件上传功能适合你么。
示例代码:
//设置允许用户上传的文件类型。
$type = array('gif', 'jpg', 'png', 'zip', 'rar');
$upload = new uploadfile($_files['uploadfile'], '/', 1024*1024, $type);
参数说明:1:表单的文件,2:上传目录,3:支持文件大小,4:允许文件类型
$icount = $upload->upload();
if($icount > 0) { //上传成功
print_r($upload->getsaveinfo());
*/
class uploadfile {
var $postfile = array(); // 用户上传的文件
var $custompath = ""; // 自定义文件上传路径
var $maxsize = ""; // 文件最大尺寸
var $lasterror = ""; // 最后一次出错信息
var $allowtype = array('gif', 'jpg', 'png', 'zip', 'rar', 'txt', 'doc', 'pdf');
var $endfilename = ""; // 最终保存的文件名
var $saveinfo = array(); // 保存文件的最终信息
var $root_dir = ""; // 项目在硬盘上的位置
/**
* 构造函数
* @access public
*/
function uploadfile($arrfile, $path="_", $size = 2097152, $type = 0) {
$this->postfile = $arrfile;
$this->custompath = $path == "_" ? "" : $path ;
$this->maxsize = $size;
if($type!=0) $this->allowtype = $arrfile;
$this->root_dir = $_server['document_root'];
$this->_mkdir($this->custompath);
}
/**
* 文件上传的核心代码
* @access public
* @return int 上传成功文件数
*/
function upload() {
$ilen = sizeof($this->postfile['name']);
for($i=0;$i<$ilen;$i++){
if ($this->postfile['error'][$i] == 0) { //上传时没有发生错误
//取当前文件名、临时文件名、大小、扩展名,后面将用到。
$sname = $this->postfile['name'][$i];
$stname = $this->postfile['tmp_name'][$i];
$isize = $this->postfile['size'][$i];
$stype = $this->postfile['type'][$i];
$sextn = $this->_getextname($sname);
//检测当前上传文件大小是否合法。
if($this->_checksize){
$this->lasterror = "您上传的文件[".$sname."],超过系统支持大小!";
$this->_showmsg($this->lasterror);
continue;
}if(!is_uploaded_file($stname)) {
$this->lasterror = "您的文件不是通过正常途径上传!";
$this->_showmsg($this->lasterror);
continue;
}
$_filename = basename($sname,".".$sextn)."_".time().".".$sextn;
$this->endfilename = $this->custompath.$_filename;
if(!move_uploaded_file($stname, $this->root_dir.$this->endfilename)) {
$this->lasterror = $this->postfile['error'][$i];
$this->_showmsg($this->lasterror);
continue;
}//存储当前文件的有关信息,以便其它程序调用。
$this->save_info[] = array("name" => $sname, "type" => $sextn, "size" => $isize, "path" => $this->endfilename);
}
}return sizeof($this->save_info);
}
1 2 3
http://www.bkjia.com/PHPjc/444829.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444829.htmlTechArticle三款php多文件上传实例代码在php开发应用中经常会碰到文件上传这个需,有时也会碰到要多文件上传,下面我们就来看看我提供的三款php多...
内容总结
以上是互联网集市为您收集整理的三款php多文件上传实例代码(1/3)_PHP教程全部内容,希望文章能够帮你解决三款php多文件上传实例代码(1/3)_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。