我在尋找很多東西,發現了很多關於這個問題的問題,遺憾的是沒有任何答案對我有幫助。CodeIgniter「您正試圖上傳的文件類型是不允許的。」
我想上傳一個PNG圖像,並且我收到以下錯誤:
The filetype you are attempting to upload is not allowed.
我這個CI指南建立我的代碼如下:http://codeigniter.com/user_guide/libraries/file_uploading.html
這裏是我的得到:
視圖文件:
[..]
<?= form_open_multipart() ?>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
<?= form_close() ?>
[..]
我的控制器:
$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();
}
正如你所看到的我試着去var_dump
mime類型和結果是空的。
當我做var_dump($_FILES)
看起來一切都很好:
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) } }
而且,我'png' => array('image/png', 'image/x-png'),
線,在我config/mimes.php
。
但是,它確實發生了所有圖像(還沒有嘗試過其他擴展名)。
我會很感激每一次幫助嘗試。
有云10,我不是一個類型的文件(MP3),但幫我解決我的問題 – 2017-01-31 00:47:17