在Codeigniter中上传svg文件

时间:2013-03-21 13:29:34

标签: php codeigniter

我正在尝试在Codeigniter中上传类型为svg的文件。但我无法使用上传库中内置的codeignite来实现。我试图通过在congig中添加这一行来实现。 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();

有人可以帮我吗?

提前致谢

3 个答案:

答案 0 :(得分:1)

$config['allowed_types'] = 'image/svg+xml';

这应该是:

$config['allowed_types'] = 'svg';

答案 1 :(得分:1)

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

$config['allowed_types'] = 'svg';

答案 2 :(得分:0)

首先,检查图片的 MIME 类型 here

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

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

'svg'   =>  array('image/svg+xml', 'application/xml', 'text/xml', 'image/svg')
相关问题