| 以下为引用的内容: // 文件格式检查,MIME检测 function validateFormat(){ if(!is_array($this->fileFormat) || in_array(strtolower($this->ext), $this->fileFormat) || in_array(strtolower($this->returninfo['type']), $this->fileFormat) ) return true; else return false; } //获取文件扩展名 function getExt($fileName){ $ext = explode(".", $fileName); $ext = $ext[count($ext) - 1]; $this->ext = strtolower($ext); } //设置上传文件的最大字节限制 // @param $maxSize 文件大小(bytes) 0:表示无限制 function setMaxsize($maxSize){ $this->maxSize = $maxSize; } //设置文件格式限定 // @param $fileFormat 文件格式数组 function setFileformat($fileFormat){ if(is_array($fileFormat)){$this->fileFormat = $fileFormat ;} } //设置覆盖模式 // @param overwrite 覆盖模式 1:允许覆盖 0:禁止覆盖 function setOverwrite($overwrite){ $this->overwrite = $overwrite; } //设置保存路径 // @param $savePath 文件保存路径:以 "/" 结尾,若没有 "/",则补上 function setSavepath($savePath){ $this->savePath = substr( str_replace("\","/", $savePath) , -1) == "/" ? $savePath : $savePath."/"; } //设置缩略图 // @param $thumb = 1 产生缩略图 $thumbWidth,$thumbHeight 是缩略图的宽和高 function setThumb($thumb, $thumbWidth = 0,$thumbHeight = 0){ $this->thumb = $thumb; if($thumbWidth) $this->thumbWidth = $thumbWidth; if($thumbHeight) $this->thumbHeight = $thumbHeight; } //设置文件保存名 // @saveName 保存名,如果为空,则系统自动生成一个随机的文件名 function setSavename($saveName){ if ($saveName == ''){ // 如果未设置文件名,则生成一个随机文件名 $name = date('YmdHis')."_".rand(100,999).'.'.$this->ext; } else { $name = $saveName; } $this->saveName = $name; } //删除文件 // @param $file 所要删除的文件名 function del($fileName){ if(!@unlink($fileName)){ $this->errno = 15; return false; } return true; } // 返回上传文件的信息 function getInfo(){ return $this->returnArray; } // 得到错误信息 function errmsg(){ $uploadClassError = array( 0 =>'There is no error, the file uploaded with success. ', 1 =>'The uploaded file exceeds the upload_max_filesize directive in php.ini.', 2 =>'The uploaded file exceeds the MAX_FILE_SIZE that was specified in the HTML form.', 3 =>'The uploaded file was only partially uploaded. ', 4 =>'No file was uploaded. ', 6 =>'Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3. ', 7 =>'Failed to write file to disk. Introduced in PHP 5.1.0. ', 10 =>'Input name is not unavailable!', 11 =>'The uploaded file is Unallowable!', 12 =>'Directory unwritable!', 13 =>'File exist already!', 14 =>'File is too big!', 15 =>'Delete file unsuccessfully!', 16 =>'Your version of PHP does not appear to have GIF thumbnailing support.', 17 =>'Your version of PHP does not appear to have JPEG thumbnailing support.', 18 =>'Your version of PHP does not appear to have pictures thumbnailing support.', 19 =>'An error occurred while attempting to copy the source image . Your version of php ('.phpversion().') may not have this image type support.', 20 =>'An error occurred while attempting to create a new image.', 21 =>'An error occurred while copying the source image to the thumbnail image.', 22 =>'An error occurred while saving the thumbnail image to the filesystem. Are you sure that PHP has been configured with both read and write access on this folder?', ); if ($this->errno == 0) return false; else return $uploadClassError[$this->errno]; } } ?> |