Php multi-file download, file download encapsulation

Source: Internet
Author: User
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.