【问题标题】:Uploading svg file in Codeigniter在 Codeigniter 中上传 svg 文件
【发布时间】:2013-03-11 01:08:44
【问题描述】:

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

谁能帮帮我?

提前致谢

【问题讨论】:

  • But i could not do it。为什么?什么错误?
  • @Bibhas -- 这是错误 ----- 您尝试上传的文件类型不被允许。
  • 在问题中指定。另外显示您用于上传的代码。
  • @rafi_ccj 从我从文档中看到的,allowed_type 选项应该是这样的$config['allowed_types'] = 'gif|jpg|png'; 尝试将svg 放在那里。
  • @rafi_ccj 正在查看this answer 的类似问题,前提是您已将 SVG mime 类型正确添加到 mime.php(您似乎已经完成),您需要做的就是通过svg 作为允许的类型,而不是 mime 类型本身。

标签: php codeigniter


【解决方案1】:

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

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

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

'svg'   =>  array('image/svg+xml', 'application/xml', 'text/xml', 'image/svg')

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:
      $config['allowed_types'] = 'image/svg+xml';
      

      这应该是:

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

      【讨论】:

        猜你喜欢
        • 2017-11-27
        • 1970-01-01
        • 2016-03-11
        • 2019-01-22
        • 2013-02-12
        • 2020-02-05
        • 1970-01-01
        • 2011-10-19
        • 2011-11-06
        相关资源
        最近更新 更多