在 Codeigniter 中上传 svg 文件

raf*_*afi 1 php codeigniter

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

'svgz' => 'image/svg+xml',
'svg' => 'image/svg+xml',
Run Code Online (Sandbox Code Playgroud)

但仍然没有解决办法。我收到此错误 -

The filetype you are attempting to upload is not allowed.
Run Code Online (Sandbox Code Playgroud)

这是我的代码

                    $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();
Run Code Online (Sandbox Code Playgroud)

有人可以帮我吗?

提前致谢

小智 5

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

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

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

'svg'   =>  array('image/svg+xml', 'application/xml', 'text/xml', 'image/svg')
Run Code Online (Sandbox Code Playgroud)