2 codeigniter file Batch Upload controller example, CodeIgniter notation
Example one:
/** * Multi-File Upload * * @author Dream
*/public function multiple_uploads () { //load the required class library $this->load- >library (' upload '); Configure the upload parameters $upload _config = Array ( ' upload_path ' = = ', ' allowed_types ' = ' jpg|png|gif ', ' max_size ' = ' + ' , ' max_width ' = ' ' 1024x768 ', ' max_height ' and ' 768 ', ; $this->upload->initialize ($upload _config); Loop process upload file foreach ($_files as $key = = $value) { if (!empty ($key [' name '])) { if ($this->upload- >do_upload ($key)) { //upload successful print_r ($this->upload->data ()); } else { //upload failed echo $this->upload->display_errors ();
}}}
Example two:
function upload () {$config [' upload_path '] = './uploads/'; /* Here uploads is relative to the index.php, that is, the entry file, this must not be mistaken Oh! Otherwise you will get an error "The upload path does not appear to be valid."; */$config [' allowed_types '] = ' gif|jpg|png '; /* I try to upload other types of files, here must pay attention to the order! A problem is encountered while attempting to move the uploaded file to the final destination. This error is generally uploaded file filename can not be Chinese name, this is very depressed! Not resolved, you can use other methods, re-change the file name can be solved! $config [' allowed_types '] = ' zip|gz|png|gif|jpg ';(correct) $config [' allowed_types '] = ' png|gif|jpg|zip|gz ';(error) */$con fig[' max_size '] = ' 1024 '; $config [' max_width '] = ' 1024 '; $config [' max_height '] = ' 768 '; $config [' file_name '] = time (); The file name does 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 some information $img = $data [' upload_data '] [' file_name '];//Fetch Get the file name Echo $img. "
"; foreach ($data [' Upload_data '] as $item = + $value) {echo $item. ":". $value. "
"; } }}
Questions about 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 it plus?
Absolute path of CodeIgniter file after uploading
Because using the upload class you can set the upload directory
So this time in fact you know the direct directory, that corresponding to the database as long as the storage file name can be
If the directory is variable (for example, by month and day), because you know it beforehand, you can also organize the corresponding relative path to store the database.
If it is written in the corresponding configuration file, it can be used when the variable
http://www.bkjia.com/PHPjc/848799.html www.bkjia.com true http://www.bkjia.com/PHPjc/848799.html techarticle 2 codeigniter File Batch Upload Controller example, codeigniter example one:/** * multiple File Upload * * @author Dream dream@shanjing-inc.com */public function m Ultiple_up ...