php多文件上传,文件上传封装
/**
?* add by huangwenyuan 2011-7-27 多文件上传,返回一个数组,该数组内存放数组,每个数组包含文件上传的随机码文件名和真实文件名
?* Enter description here ...
?* @param unknown_type $formFilename
?* @param unknown_type $filePath
?* @param unknown_type $newFileName
?* @param unknown_type $fileTypeArray
?* @param unknown_type $fileMaxSize
?*/
function filesUpload($formFilename, $filePath,
?????????????? $fileTypeArray= array('image/pjpeg','application/pdf'), $fileMaxSize = 2000000){
???? $file_num = count($_FILES[$formFilename]['name']);//获取文件上传个数
? $msgPaths = array();
????
???? for ($i = 0; $i ???? ?$file_name = $_FILES[$formFilename]['name'][$i];
??$file_type = $_FILES[$formFilename]['type'][$i];
??$file_temp = $_FILES[$formFilename]['tmp_name'][$i];
??$file_size = $_FILES[$formFilename]['size'][$i];
??$file_error = $_FILES[$formFilename]['error'][$i];
??
??if($file_error>0){
???$msg = 1;
????? switch($file_error) {
???????????? case 1: $msg = 2; break;
???????????? case 2: $msg = 2; break;
???????????? case 3: $msg = 3; break;
???????????? case 4: $msg = -1; break;
???????? }
??}else if($file_size > $fileMaxSize){
???$msg = 2;
??}else if(! in_array($file_type, $fileTypeArray)){
???$msg = 4;
??}else if(! f_createDirN($filePath)){
???$msg = 5;
??}else{
???$ext = f_getExt($file_name); //扩展名
???$new_file_name = f_random().$ext;
?
???//$fileName = iconv("utf-8","gbk",$fileName); //处理中文乱码
???move_uploaded_file($file_temp, $filePath . iconv("utf-8","gbk",$new_file_name));???
???$msg = 0;
??}
??
??$msgPath = array(
????? 'filePath' => $filePath.$new_file_name,
???'fileName' =>$file_name
??);
??
??$msgPaths[$i] = $msgPath;
?? ?}????
?? ?return $msgPaths;
}