1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > php多个文件上传代码 PHP单文件上传类或多文件上传类源码

php多个文件上传代码 PHP单文件上传类或多文件上传类源码

时间:2020-11-10 14:31:17

相关推荐

php多个文件上传代码 PHP单文件上传类或多文件上传类源码

以下为引用的内容:

php文件:

代码:

//如果收到表单传来的参数,则进行上传处理,否则显示表单

if(isset($_FILES['uploadinput'])){

//建目录函数,其中参数$directoryName最后没有"/",

//要是有的话,以'/'打散为数组的时候,最后将会出现一个空值

function makeDirectory($directoryName) {

$directoryName = str_replace("\","/",$directoryName);

$dirNames = explode('/', $directoryName);

$total = count($dirNames) ;

$temp = '';

for($i=0; $i

$temp .= $dirNames[$i].'/';

if (!is_dir($temp)) {

$oldmask = umask(0);

if (!mkdir($temp, 0777)) exit("不能建立目录 $temp");

umask($oldmask);

}

}

return true;

}

if($_FILES['uploadinput']['name'] <> ""){

//包含上传文件类

require_once ('class_upload.php');

//设置文件上传目录

$savePath = "upload";

//创建目录

makeDirectory($savePath);

//允许的文件类型

$fileFormat = array('gif','jpg','jpge','png');

//文件大小限制,单位: Byte,1KB = 1000 Byte

//0 表示无限制,但受php.ini中upload_max_filesize设置影响

$maxSize = 0;

//覆盖原有文件吗? 0 不允许 1 允许

$overwrite = 0;

//初始化上传类

$f = new clsUpload( $savePath, $fileFormat, $maxSize, $overwrite);

//如果想生成缩略图,则调用成员函数 $f->setThumb();

//参数列表: setThumb($thumb, $thumbWidth = 0,$thumbHeight = 0)

//$thumb=1 表示要生成缩略图,不调用时,其值为 0

//$thumbWidth 缩略图宽,单位是像素(px),留空则使用默认值 130

//$thumbHeight 缩略图高,单位是像素(px),留空则使用默认值 130

$f->setThumb(1);

//参数中的uploadinput是表单中上传文件输入框input的名字

//后面的0表示不更改文件名,若为1,则由系统生成随机文件名

if (!$f->run('uploadinput',0)){

//通过$f->errmsg()只能得到最后一个出错的信息,

//详细的信息在$f->getInfo()中可以得到。

echo $f->errmsg()."

n";

}

//上传结果保存在数组returnArray中。

echo "

";

print_r($f->getInfo());

echo "

";

}

}else{

?>

Send this file:

}

//我们上传一个已经存在了的图片文件,

//一个正常的图片文件,和一个不允许上传的文件,

//输出结果如下

/*

The uploaded file is Unallowable!

Array

(

[0] => Array

(

[name] => boy.jpg

[saveName] => boy.jpg

[size] => 137

[type] => image/pjpeg

[error] => File exist already!

)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。