This article mainly introduces two examples of Codeigniter file batch upload controller writing. For more information, see
Example 1:
/*** Multifile upload *** @ author Dream
*/Public function multiple_uploads () {// load the required class library $ this-> load-> library ('upload '); // configure the upload parameter $ upload_config = array ('upload _ path' => '', 'allowed _ types '=> 'jpg | png | gif ', 'max _ size' => '123', 'max _ width' => '123', 'max _ height' => '123 ',); $ this-> upload-> initialize ($ upload_config); // process uploaded file foreach cyclically ($ _ FILES as $ key => $ value) {if (! Empty ($ key ['name']) {if ($ this-> upload-> do_upload ($ key )) {// print_r ($ this-> upload-> data ());} else {// upload Failed echo $ this-> upload-> display_errors ();}}}}
Example 2:
Function upload () {$ config ['upload _ path'] = '. /uploads/';/* Here, uploads is relative to index. php, that is, the entry file. Do not make a mistake! Otherwise, The error "The upload path does not appear to be valid. "; */$ config ['allowed _ types '] = 'gif | jpg | png';/* I tried to upload other types of files. Pay attention to the sequence here! A problem was encountered while attempting to move the uploaded file to the final destination. This error is generally because the file name to be uploaded cannot be A Chinese name. This is depressing! Not solved yet. You can use other methods to solve the problem by modifying the file name! $ Config ['allowed _ types'] = 'zip | gz | png | gif | jpg '; (correct) $ config ['allowed _ types'] = 'png | gif | jpg | zip | gz '; (error) */$ config ['max _ size'] = '000000'; $ config ['max _ width'] = '000000 '; $ config ['max _ height'] = '000000'; $ config ['file _ name'] = time (); // do not use the original name $ this-> load-> library ('upload', $ config); if (! $ This-> upload-> do_upload () {echo $ this-> upload-> display_errors ();} else {$ data ['upload _ data'] = $ this-> upload-> data (); // file Information $ img = $ data ['upload _ data'] ['file _ name']; // obtain the file name echo $ img."
"; Foreach ($ data ['upload _ data'] as $ item => $ value) {echo $ item.": ". $ value ."
";}}}