Welcome Guest, Not a member yet? Register   Sign In
Upload excel file codeigniter
#1

I'm trying to upload excel file. But it's not working. Please check my script

 

 
Code:
 function proses()
   {  
       extract(populateform());
       $config = array(
       'upload_path' => "./assets_global/file_upload/",
       'allowed_types' => "xls|XLSX",
       'overwrite' => TRUE,
       'max_size' => "2048000000",
       'file_name' => 'blablabla'
       );      
       $this->upload->initialize($config);
       $this->load->library('upload', $config);
       $upload_data = $this->upload->data();
       if($this->upload->do_upload())          
       {
       echo "sukses";
       }else{
       echo $this->upload->display_errors();
       }
   }



my mimes


Code:
   'xlsx'  =>  array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip'), 'word' => array('application/msword', 'application/octet-stream'),
   'xls'   =>  array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),


When i'm upload file. I always get this result `The filetype you are attempting to upload is not allowed.`

The result of `print_r($this->upload->data());`

 
Code:
 Array
   (
       [file_name] => tes import.xlsx
       [file_type] => application/octet-stream
       [file_path] => D:/xampp/htdocs/payroll/assets_global/file_upload/
       [full_path] => D:/xampp/htdocs/payroll/assets_global/file_upload/tes import.xlsx
       [raw_name] => tes import
       [orig_name] =>
       [client_name] => tes import.xlsx
       [file_ext] => .xlsx
       [file_size] => 8277
   )
Reply
#2

(04-21-2016, 07:46 PM)bobykurniawan Wrote: I'm trying to upload excel file. But it's not working. Please check my script

 

 
Code:
 function proses()
   {  
       extract(populateform());
       $config = array(
       'upload_path' => "./assets_global/file_upload/",
       'allowed_types' => "xls|XLSX",
       'overwrite' => TRUE,
       'max_size' => "2048000000",
       'file_name' => 'blablabla'
       );      
       $this->upload->initialize($config);
       $this->load->library('upload', $config);
       $upload_data = $this->upload->data();
       if($this->upload->do_upload())          
       {
       echo "sukses";
       }else{
       echo $this->upload->display_errors();
       }
   }



my mimes


Code:
   'xlsx'  =>  array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip'), 'word' => array('application/msword', 'application/octet-stream'),
   'xls'   =>  array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),


When i'm upload file. I always get this result `The filetype you are attempting to upload is not allowed.`

The result of `print_r($this->upload->data());`

 
Code:
 Array
   (
       [file_name] => tes import.xlsx
       [file_type] => application/octet-stream
       [file_path] => D:/xampp/htdocs/payroll/assets_global/file_upload/
       [full_path] => D:/xampp/htdocs/payroll/assets_global/file_upload/tes import.xlsx
       [raw_name] => tes import
       [orig_name] =>
       [client_name] => tes import.xlsx
       [file_ext] => .xlsx
       [file_size] => 8277
   )


Did you forget  add enctype="multipart/form-data" like this ?
<form action="your controller" method="post" enctype="multipart/form-data">
Reply




Theme © iAndrew 2016 - Forum software by © MyBB