Example of how to write two Codeigniter files for batch upload controller and codeigniter _ PHP Tutorial

Source: Internet
Author: User
Two examples of how to write a batch upload controller for Codeigniter files and codeigniter. Two Codeigniter file batch upload controller writing example, codeigniter writing Example 1: *** multifile Upload *** @ authorDreamdream@shanjing-inc.com * publicfunctionmultiple_up two Codeigniter file batch upload controller writing example, codeigniter writing example

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 ."
";}}}


What are the issues with CodeIgniter access?

Local Address/CodeIgniter/index. php? /
Local Address/CodeIgniter/index. php? /Welcome
Local Address/CodeIgniter/index. php? /Welcome/
Local Address/CodeIgniter/index. php? /Welcome/index
Local Address/CodeIgniter/index. php? /Welcome/index/
Try to add?

The absolute path obtained after the codeigniter file is uploaded

You can set the upload directory by using the Upload class.
So at this time, you actually know the direct directory, and the corresponding stored database only needs to store the file name.

If the directory is changed (for example, by year, month, or day), because you know it in advance, you can also organize the corresponding relative path to store it in the database.

If it is written in the corresponding configuration file, you can use

Example 1:/*** multifile Upload ** @ author Dream dream@shanjing-inc.com */public function multiple_up...

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.