php:上传多个文件
<?php
class upload
{
public $files;
public $seterror;
public $allowtype;
public $filetype;
public $typeerror;
public $path;
public $succ=0;
public $filenewname;
function __construct($files,$path)
{
$this->path=$path;
$this->files=$files;
$this->seterror=1;
$this->allowtype=array("jpg","gif","JPG","png","jpeg");
$this->filetype=array();
$this->filenewname=array();
if(is_array($_FILES[$files]['name']))
{
foreach($_FILES[$files]['name'] as $key => $names)
{
$file_ex=explode(".",$names);
$this->filetype[$key]=$file_ex[count($file_ex)-1];
$this->filenewname[$key]=$this->path.time().$key.".".$this->filetype[$key];
}
foreach($this->filetype as $key => $type)
{
if(!in_array($type,$this->allowtype))
{
$this->typeerror=$key+1;
$this->seterror="第".$this->typeerror."张图片类型不符合要求";
echo $this->seterror;
exit;
}
}
foreach($_FILES[$files]['error'] as $val)
{
if($val!=0)
{
switch($val)
{
case 1:;
case 2:$this->seterror="上传的文件过大,最大能上传2M";break;
case 3:$this->seterror="文件只有部分被上传";break;
case 4:$this->seterror="文件没有被上传";break;
case 6:$this->seterror="找不到临时文件夹";break;
case 7:$this->seterror="文件写入失败";break;
}
echo $this->seterror;
exit;
}
}
}
if(!file_exists($path))
{
mkdir($path,0777);
}
if($this->seterror==1)
{
$this->move_file();
}
}
private function move_file()
{
foreach($_FILES[$this->files]['tmp_name'] as $key => $tmp)
{
if(move_uploaded_file($tmp,$this->filenewname[$key]))
{
$this->succ+=1;
}
}
if($this->succ==count($_FILES[$this->files]['name']))
{
echo "全部上传成功";
}
}
}
?>
php:上传多个文件的更多相关文章
- 强大的支持多文件上传的jQuery文件上传插件Uploadify
支持多文件上传的jQuery文件上传插件Uploadify,目前此插件有两种版本即Flash版本和HTML5版本,对于HTML5版本会比较好的支持手机浏览器,避免苹果手机Safari浏览器不支持Fla ...
- spring mvc文件上传(单个文件上传|多个文件上传)
单个文件上传spring mvc 实现文件上传需要引入两个必须的jar包 1.所需jar包: commons-fileupload-1.3.1.jar ...
- SecureCRT上传和下载文件
SecureCRT上传和下载文件(下载默认目录) SecureCR 下的文件传输协议有ASCII .Xmodem .Ymodem .Zmodem ASCII:这是最快的传输协议,但只能传送文本文件. ...
- thinkphp如何一次性的上传多个文件,在文件域中可以多选?
可以做到类似于某度网盘的样式吗? 文件夹的命名, 可以用单数, 也可以用复数, 在同一个项目中, 只要统一就好了. 毕竟项目开发不同于英语写作. 建议使用缩写, 不管是不是缩写都用单数, 这样简洁,容 ...
- Drupal8重命名上传的中文名文件
完整的模块代码文件在Coding.net上,想直接使用的请前往下载:https://coding.net/u/yamus/p/chinese_rename/git/tree/master 最近吧Dru ...
- WordPress上传含有中文文件出现乱码
最近打算学习安装配置WordPress,当然同时也在学习PHP+MySQL,希望以后能做一些关于WordPress定制和二次开发,包括主题和插件.在成功安装WordPress3.5中文版之后,就测试了 ...
- 11、只允许在主目录下上传和下载文件,不允许用putty登录
创建用户xiao, 使其只允许在用户主目录 (/var/www/html)下上传和下载文件,不允许用putty登录 (为了安全起见,不给过多的权限) 1.创建xiao用户 [root@localh ...
- 每天一个linux命令(26):用SecureCRT来上传和下载文件
用SSH管理linux服务器时经常需要远程与本地之间交互文件.而直接用SecureCRT自带的上传下载功能无疑是最方便的,SecureCRT下的文件传输协议有ASCII.Xmodem.Zmodem. ...
- BatsingJSLib 2.3、Ajax上传多个文件
//2.3Ajax上传单个或多个文件 //<input type="file" multiple="multiple"/> //参数:文件的表单JD ...
- 上传读取Excel文件数据
/// <summary> /// 上传读取Excel文件数据 /// 来自http://www.cnblogs.com/cielwater /// </summary> // ...
随机推荐
- 深入浅出设计模式——工厂方法模式(Factory Method)
介绍在简单工厂模式中,我们提到,工厂方法模式是简单工厂模式的一个延伸,它属于Gof23中设计模式的创建型设计模式.它解决的仍然是软件设计中与创建对象有关的问题.它可以更好的处理客户的需求变化. 引入我 ...
- 五大权限:UGO权限、SetUID SetGID Sticky、ACL权限、chattr(文件系统级别的权限)、SELINUX
五大权限:UGO权限.SetUID SetGID Sticky.ACL权限.chattr(文件系统级别的权限).SELINUX ======================文件属性以及ugo权限= ...
- do while(false)实用技巧
今天看项目源码的时候发现有些地方用了do{} while(false)的用法,查了下发现这样确实有些优点,mark下. 1.最重要的优点,用在略微复杂的宏定义中. #define AB1 a; b; ...
- MTF(Move-to-front transform)数据转换
1.什么是MTF MTF(move-to-front)是一种数据编码方式,用于提高数据压缩技术效果. 在数据压缩算法中,MTF可以作为一个额外的步骤.也就是说 ,可以先进行MTF编码,在进行数据压缩. ...
- js时间格式转换
在javascript中直接输出Date得到的结果是这样的: function date(){ var date = new Date(); alert(date); } 结果是:Mon Jun 15 ...
- Running With xpi
d File file = new File("firebug-1.8.1.xpi"); FirefoxProfile firefoxProfile = new FirefoxPr ...
- Linux 系统目录结构
登录系统后,在当前命令窗口下输入命令: ls / 你会看到如下图所示: 树状目录结构: 以下是对这些目录的解释: /bin: bin是Binary的缩写, 这个目录存放着最经常使用的命令. /boot ...
- UVA 1349(二分图匹配)
1349 - Optimal Bus Route Design Time limit: 3.000 seconds A big city wants to improve its bus transp ...
- [ie兼容]ie7浮动左在前,浮动右在后导致右边浮动的元素掉下来
解决办法:左浮动和右浮动元素在结构上互换位置 http://blog.sina.com.cn/s/blog_818a1e5b0100wp5b.html
- c# 配置文件之configSections配置(三)
使用IConfigurationSectionHandler配置configSections ·步骤1:定义一个实体类 using System; using System.Collections.G ...