繁体   English   中英

在 Codeigniter 中上传 svg 文件

[英]Uploading svg file in Codeigniter

我正在尝试在 Codeigniter 中上传类型为 svg 的文件。 但是我无法使用上传库中内置的代码点火器来做到这一点。 我试图通过在 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();

有人可以帮我吗?

提前致谢

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

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

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

'svg'   =>  array('image/svg+xml', 'application/xml', 'text/xml', 'image/svg')
$config['allowed_types'] = 'image/svg+xml';

这应该是:

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM