欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php多文件下传,文件下传封装

程序员文章站 2022-05-12 17:11:21
...
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;
}

php多文件下传,文件下传封装

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频