标签:io ar sp for 文件 on cti bs ad
<?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 "全部上传成功";
}
}
}
?>
标签:io ar sp for 文件 on cti bs ad
原文地址:http://www.cnblogs.com/xiaoying1019/p/4098002.html