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.