do upload is accepting .zip files instead of giving error |
-
kari0891
Newbie
-
Posts: 1
Threads: 0
Joined: Aug 2018
Reputation:
0
08-02-2018, 01:15 AM
In Codeigniter 2.3 allowed_types validation is not working correctly. We can try the below alternative by creating your own custom array of mime types and validating it
<?php
if(!empty($_FILES['img1']['name'])){
$config['upload_path'] = 'uploads/images/';
$config['allowed_types'] = '*';
$config['file_name'] = $_FILES['img1']['name'];
//create your custom mime types array to be checked. In the below have added various types of CSV file
$csv_mime_type = array('text/plain','text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel');
//Load upload library and initialize configuration
$this->load->library('upload',$config);
$this->upload->initialize($config);
if(!$this->upload->do_upload("img1")){
$error = array('error'=>$this->upload->display_errors());
$this->session->set_flashdata('error',$error['error']);
redirect('my_controller/profile');
}
elseif(!in_array($_FILES['img1']['type'], $csv_mime_type)) { //check filetype is in csv format
//error handling
}
else{
$img1 = $this->upload->data();
$timg1 = $img1['file_name'];
}
}
?>
|
Messages In This Thread |
RE: do upload is accepting .zip files instead of giving error - by kari0891 - 08-02-2018, 01:15 AM
|