Multiple file upload support for CodeIgniter 2.x.
Note: CodeIgniter doesn't have predefined function for the multiple file upload. So i had recently Got the Multiple file upload library from the Git Hup. so you can easily use this function for the single and multiple file uploads
Click here to get this library and copy to the "CodeIgniter/application/libraries/" folder
the below is the program to upload multiple files
<?php
class Log extends CI_Controller{
public function index(){
echo $this->load->view('r');
}
public function up(){
$this->load->library('form_validation');
$this->load->helper(array('form','url'));
$config['upload_path']="./uploads/";
$config['allowed_types']='jpg|jpeg|gif|png';
$config['overwrite']=TRUE;
$this->load->library('upload',$config);
$field_name="logo";
if(!$this->upload->do_multi_upload($field_name)){
$data=array('err'=>$this->upload->display_errors());
}else{
$file_data=$this->upload->data();
$data['img']=base_url().'/uploads/'.$file_data['file_name'];
$this->load->view('r',$data);
}
}
}
(View) r.php
<?php
if(isset($msg)) echo "$msg";
if(isset($err)) echo $err;
echo validation_errors();
echo form_open_multipart('log/up', 'method=post');
echo form_upload('logo[]','','multiple');
echo form_submit('submit', 'register');
echo form_close();
?>
Note: CodeIgniter doesn't have predefined function for the multiple file upload. So i had recently Got the Multiple file upload library from the Git Hup. so you can easily use this function for the single and multiple file uploads
Click here to get this library and copy to the "CodeIgniter/application/libraries/" folder
the below is the program to upload multiple files
<?php
class Log extends CI_Controller{
public function index(){
echo $this->load->view('r');
}
public function up(){
$this->load->library('form_validation');
$this->load->helper(array('form','url'));
$config['upload_path']="./uploads/";
$config['allowed_types']='jpg|jpeg|gif|png';
$config['overwrite']=TRUE;
$this->load->library('upload',$config);
$field_name="logo";
if(!$this->upload->do_multi_upload($field_name)){
$data=array('err'=>$this->upload->display_errors());
}else{
$file_data=$this->upload->data();
$data['img']=base_url().'/uploads/'.$file_data['file_name'];
$this->load->view('r',$data);
}
}
}
(View) r.php
<?php
if(isset($msg)) echo "$msg";
if(isset($err)) echo $err;
echo validation_errors();
echo form_open_multipart('log/up', 'method=post');
echo form_upload('logo[]','','multiple');
echo form_submit('submit', 'register');
echo form_close();
?>
0 comments:
Post a Comment