1

我正在尝试在 Codeigniter 中上传 svg 类型的文件。但是我无法使用上传库中内置的 codeigniters 来做到这一点。我试图通过在 conig > mimes.php 文件中添加这一行来做到这一点

'svgz' => 'image/svg+xml',
'svg' => 'image/svg+xml',

但仍然没有解决方案。我收到此错误 -

The filetype you are attempting to upload is not allowed.

这是我的代码

                    $dir = 'uploads/svg/';
                    $this->load->library('upload');

                    $config['file_name'] = $result . '.svg';
                    $config['upload_path'] = $dir;
                    $config['allowed_types'] = 'image/svg+xml';

                    $this->load->library('upload');
                    $this->upload->initialize($config);
                    $this->upload->do_upload();

任何人都可以帮助我吗?

提前致谢

4

3 回答 3

4

首先,在此处检查图像的 MIME 类型

然后,从 config 文件夹中打开mimes.php,然后从数组中找到与您的图像扩展名相同的索引数组元素,将图像的 mime 类型添加到数组中

就我而言,我添加了“图像/svg”:

'svg'   =>  array('image/svg+xml', 'application/xml', 'text/xml', 'image/svg')
于 2021-03-25T12:06:47.510 回答
1

您需要将允许的文件扩展名列表放在 中$config['allowed_types'],用 分隔|,而不是 MIME 类型。尝试这个 -

$config['allowed_types'] = 'svg';
于 2013-03-21T13:48:21.053 回答
1
$config['allowed_types'] = 'image/svg+xml';

这应该是:

$config['allowed_types'] = 'svg';
于 2013-03-21T13:48:16.503 回答