Home >php教程 >php手册 >自己写的一个PHP上传类

自己写的一个PHP上传类

WBOY
WBOYOriginal
2016-06-13 10:03:001163browse

主要功能:
文件上传,获取文件名,获取文件大小,随机生成新文件名,获取文件类型,图片生成缩略图,返回缩略图文件名,返回上传后生成的文件的文件名,返回上传后的文件路径

class ieb_upload{
var $FormName; //文件域名称
var $Directroy; //上传至目录
var $MaxSize; //最大上传大小
var $CanUpload; //是否可以上传
var $doUpFile; //上传的文件名
var $sm_File; //缩略图名称
var $Error; //错误参数

function ieb_upload($formName='', $dirPath='', $maxSize=2097152) //(1024*2)*1024=2097152 就是 2M
{
global $FormName, $Directroy, $MaxSize, $CanUpload, $Error, $doUpFile, $sm_File;
//初始化各种参数
$FormName = $formName;
$MaxSize = $maxSize;
$CanUpload = true;
$doUpFile = '';
$sm_File = '';
$Error = 0;

if ($formName == ''){
$CanUpload = false;
$Error = 1;
break;
}

if ($dirPath == ''){
$Directroy = $dirPath;
}else{
$Directroy = $dirPath.'/';
}
}

//检查文件是否存在
function scanFile()
{
global $FormName, $Error, $CanUpload;

if ($CanUpload){

$scan = is_readable($_FILES[$FormName]['name']);

if ($scan){
$Error = 2;
}

return $scan;
}
}


//获取文件大小
function getSize($format = 'B')
{
global $FormName, $Error, $CanUpload;

if ($CanUpload){

if ($_FILES[$FormName]['size'] == 0){
$Error = 3;
$CanUpload = false;
}

switch ($format){

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn