Example one:
/** *
Multi-File Upload * *
@author Dream <dream@shanjing-inc.com> * Public
function multiple_uploads () {
//loading the required class library
$this->load->library (' upload ');
Configure upload parameters
$upload _config = Array (
' Upload_path ' => ', '
allowed_types ' => ' jpg|png|gif '),
' max_size ' => ',
' max_width ' => ' 1024 ',
'
max_height ' => ' 768 ', ;
$this->upload->initialize ($upload _config);
Recycle Upload Files
foreach ($_files as $key => $value) {
if (!empty ($key [' name ')]) {
if ($this->upload- >do_upload ($key)) {
//upload succeeded
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, the 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 the uploaded file to the final destination.
This error is generally uploaded file filename can not be Chinese name, this is very depressed! has not been resolved, we can use other methods, the file name can be changed again to solve! $config [' allowed_types '] = ' zip|gz|png|gif|jpg ';(correct) $config [' allowed_types '] = ' png|gif|jpg|zip|gz ';(error) */$
config[' max_size '] = ' 1024 ';
$config [' max_width '] = ' 1024 ';
$config [' max_height '] = ' 768 '; $config [' file_name '] = time ();
The filename 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 ();//Documents some information $img = $data [' upload_data '] [' file_name ']; Gets the filename echo $img. " <bR> "; foreach ($data [' Upload_data '] as $item => $value) {echo $item. ":". $value. "
<br> "; }
}
}