发布个我自己写的PHP批量上传类..
php批量上传类
HTML页面部分:
<form enctype="multipart/form-data" method="post" name="upform">
上传文件: br><br>
1.<input name="upfile[]" type="file" size="30"><br><br>
2.<input name="upfile[]" type="file" size="30"><br><br>
3.<input name="upfile[]" type="file" size="30"><br><br>
4.<input name="upfile[]" type="file" size="30"><br><br>
<input type="submit" value="上传" size="17">
</form>
核心类
<?php
class FilesUpload {
var $maxsize = 0 ;
var $src_fsizes = 0;
var $sux = array ('gif', 'jpg', 'png', 'zip', 'rar', 'txt', 'doc', 'pdf');
var $dst_path = './upload';
var $dst_name = 'randstring().\'.\'.$Files[\'type\'];';
var $errver = false;
var $errfile = 0;
var $errno = 0;
var $error = ”;
var $reinfo = ”;
function __construct() {
$this->FilesUpload();
}
function FilesUpload() {
$this->maxsize = (int) ini_get ( 'upload_max_filesize' ) * 1024 * 1024;
$this->dst_path = BIGQI_ROOT.$this->dst_path;
}
function maxsize($maxsize) {
$this->maxsize = $maxsize * 1024;
//kb
}
function send($Uploadfiles) {
for ($i = 0; $i < count ( $Uploadfiles ['name'] ); $i ++) {
$upload_name = $Uploadfiles ['name'] [$i];
$upload_tmpname = $this->str_fillter ( $Uploadfiles ['tmp_name'] [$i] );
$upload_size = $Uploadfiles ['size'] [$i];
$upload_mime = $Uploadfiles ['type'] [$i];
$upload_type = getfilesux ( $Uploadfiles ['name'] [$i] );
if (!$upload_name && !$upload_tmpname && !$upload_size && !$upload_mime && !$upload_type) {
continue;
}
if ($Uploadfiles ['error'] [$i] != 0) {
$this->errver = true;
$this->errfile = $i;
$this->errno = 10;
$this->error = $Uploadfiles ['error'] [$i];
return false;
}
if (! in_array ( $upload_type, $this->sux )) {
$this->errver = true;
$this->errfile = $i;
$this->errno = 20;
$this->error = 'UploadFile type error!';
return false;
}
if (! is_uploaded_file ( $upload_tmpname )) {
$this->errver = true;
$this->errfile = $i;
$this->errno = 30;
$this->error = 'UploadFile tmpname error!';
return false;
}
if (! $upload_size ) {
continue;
} else {
$this->src_fsizes += $upload_size;
}
$DstFiles [$i] ['name'] = $upload_name;
$DstFiles [$i] ['temp'] = $upload_tmpname;
$DstFiles [$i] ['size'] = $upload_size;
$DstFiles [$i] ['type'] = $upload_type;
$DstFiles [$i] ['mime'] = $upload_mime;
}
if ($this->src_fsizes > $this->maxsize) {
$this->errver = true;
$this->errfile = $i;
$this->errno = 40;
$this->error = 'UploadFile maxsize too big!';
return false;
}
if (!$this->errver) {
$savefullpath_array = array();
foreach($DstFiles as $key =>$Files) {
$basename = basename ( $Files['name'], '.'.$Files['type'] );
do {
eval('$file_savename='.$this->dst_name.';');
$file_savefullpath = $this->dst_path . "/" . $file_savename;
}
while ( file_exists ( $file_savefullpath ) );
if (! move_uploaded_file ( $Files['temp'], $file_savefullpath )) {
$this->errver = true;
$this->errfile = $i;
$this->errno = 50;
$this->error = 'UploadFile rename error!';
foreach($savefullpath_array as $filesed) {
delfile($filesed);
}
unset($savefullpath_array);
return false;
} else {
$DstFiles[$key]['sname'] = $file_savename;
$savefullpath_array[] = $file_savefullpath;
}
}
$this->reinfo = $DstFiles;
unset($savefullpath_array,$DstFiles,$_FILES);
return $DstFiles;
}
}
function str_fillter($string) {
$string = str_replace("\\\"", "\"", $string);
$string = str_replace("\\'", "'", $string);
$string = str_replace("\\\\", "\\", $string);
return $string;
}
}
function getfilesux($filename) {
$stuff = pathinfo ( $filename );
return $stuff ['extension'];
}
//使用方法:
$upload = new FilesUpload();
$upload ->dst_path = $uploadpath;
$upload -> send($_FILES[upfile]);
var_dump ($upload -> reinfo);
?>