Php multi-file upload and file Upload encapsulation **? * Addbyhuangwenyuan2011-7-27 multi file upload, returns an array, the array memory put array, each array contains the file uploaded random code file name and real file name? * Enterdescriptionhere ...? * @ Paramunknown_type $ formFilename? * @ Paramu php multi-file upload, file Upload encapsulation
/**
? * Add by huangwenyuan 2011-7-27 multi-file upload: an array is returned, which is stored in the array. each array contains the random code file name uploaded by the file and the actual file name.
? * 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']); // Obtain the number of file uploads
? $ MsgPaths = array ();
????
???? For ($ I = 0; $ I <$ file_num; $ 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); // extension
??? $ New_file_name = f_random (). $ ext;
?
??? // $ FileName = iconv ("UTF-8", "gbk", $ fileName); // process Chinese garbled characters
??? 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;
}