php 文件上传类
<?php
/**
* 文件上传类
* 2011/9/22
* kcj
* */
class UpFile{
private $filePath; //文件目的路径
private $fileField; //默认$_FILES[$fileField],通过$_FILES环境变量获取上传文件信息
private $originName; //源文件名
private $tmpFileName; //临时文件名
private $fileType; //文件类型
private $fileSize; //文件大小
private $newFileName; //新文件名
private $allowType=array('jpg','gif','png'); //
private $maxSize=2000000; //允许文件上传的最大度是2M
private $isUserDefName=false; //是否采用用户自定义名
private $userDefName; //用户定义名称
private $isRandName=true; //是否随机命名
private $randName; //系统随机名称
private $errorNum=0; //错误号
private $isCoverModer=true; //是否覆盖模式
function __construct($options=array()){
$this->setOptions($options); //设置上传时属性列表
}
function uploadFile($filefield){
$this->setOption('errorNum',0); //设置错误位
$this->setOption('fileField',$filefield); //设置fileField
$this->setFiles(); //设置文件信息
$this->checkValid(); //判断合法性
$this->checkFilePath(); //检查文件路径
$this->setNewFileName(); //设置新的文件名
if($this->errorNum<0)
return $this->errorNum;
return $this->copyFile(); //上传文件
}
private function setOptions($options=array()){
foreach ($options as $key=>$val){
if(!in_array($key,array('filePath','fileField','originName','allowType','maxSize','isUserDefName','userDefName','isRandName','randName')))
continue;
$this->setOption($key,$val);
}
}
private function setFiles(){
if($this->getFileErrorFromFILES!=0){
$this->setOptions('errorNum',-1);
return $this->errorNum;
}
$this->setOption('originName',$this->getFileNameFromFILES());
$this->setOption('tmpFileName',$this->getTmpFileNameFromFILES());
$this->setOption('fileType',$this->getFileTypeFromFILES());
$this->setOption('fileSize',$this->getFileSizeFromFILES());
}
private function setOption($key,$val){
$this->$key=$val;
}
private function setNewFileName(){
if($this->isRandName==false&&$this->isUserDefName==false){
$this->setOption('newFileName',$this->originName);
}elseif ($this->isRandName==true&&$this->i
补充:Web开发 , php ,