CodeIgniter "The type of file you are trying to download is not allowed."

I searched a lot and found many questions regarding this problem, unfortunately, none of the answers helped me.

I try to load a png image and I get the following error:

The type of file you are trying to download is not allowed.

I followed this CI manual to create my code: http://codeigniter.com/user_guide/libraries/file_uploading.html

Here is what I got:

view file:

[..] <?= form_open_multipart() ?> <input type="file" name="userfile" size="20" /> <br /><br /> <input type="submit" value="upload" /> <?= form_close() ?> [..] 

My controller:

  $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; $config['max_width'] = '1024'; $config['max_height'] = '768'; $this->load->library('upload', $config); $xx = array('upload_data' => $this->upload->data()); $mimetype= $xx['upload_data']['file_type']; var_dump('Mime: ' . $mimetype); var_dump($_FILES); if ( !$this->upload->do_upload()) { Notice::add($this->upload->display_errors(), 'error'); } else { $data['upload_data'] = $this->upload->data(); } 

As you can see, I'm trying to use the var_dump type mime and the result is empty.

When I do var_dump($_FILES) , everything looks fine:

 array(1) { ["userfile"]=> array(5) { ["name"]=> string(14) "imageofm.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(18) "/var/tmp/php5cDAZJ" ["error"]=> int(0) ["size"]=> int(358) } } 

Also, I got the string 'png' => array('image/png', 'image/x-png'), in my config/mimes.php .

However, this happens for all images (have not tried other extensions yet).

I would be grateful for every attempt to help.

+6
source share
6 answers

Just edit the mimes.php file in the /config/mimes.php application and replace the line for csv as follows:

 'csv' => array('application/vnd.ms-excel', 'text/anytext', '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') 
+7
source

Add 'text / plain to CSV array in config / mimes.php in $ mimes arrays

+4
source

Replacing the codeigniter 2.1.0 system / libraries / upload.php with download.php version 2.1.2 solves the problem. Hope this helps

+1
source
 $this->load->library('upload'); $this->upload->set_allowed_types('*'); class MY_Upload extends CI_Upload { function is_allowed_filetype() { if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types)) { $this->set_error('upload_no_file_types'); return FALSE; } if (in_array("*", $this->allowed_types)) { return TRUE; } $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe'); foreach ($this->allowed_types as $val) { $mime = $this->mimes_types(strtolower($val)); // Images get some additional checks if (in_array($val, $image_types)) { if (getimagesize($this->file_temp) === FALSE) { return FALSE; } } if (is_array($mime)) { if (in_array($this->file_type, $mime, TRUE)) { return TRUE; } } else { if ($mime == $this->file_type) { return TRUE; } } } return FALSE; } } 
+1
source

another solution is to enable extension=php_fileinfo.dll in php.ini

0
source

I will just add this line to mime.php on line 34, and now pptx loads. test it on a real server

'pptx' => array ('application / vnd.openxmlformats-officedocument.wordprocessingml.document', 'application / zip'),

0
source

Source: https://habr.com/ru/post/912783/


All Articles