【问题标题】:Uploading svg image with CodeIgniter使用 CodeIgniter 上传 svg 图像
【发布时间】:2014-12-29 00:30:59
【问题描述】:

我尝试使用 CodeIgniter 上传 svg 文件。

$config = array(
        'upload_path' => 'path',
        'allowed_types' => 'jpg|jpeg|png|svg|gif',
        'max_size' => 'size',
        'max_width' => 'width',
        'max_height' => 'height',
        'encrypt_name' => 'TRUE',
    );

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

    if($this->upload->do_upload('image_file')) {
        echo 'Success';
    } else {
        echo $this->upload->display_errors();
    }

我已经在此链接Uploading svg file in Codeigniter 中阅读了相同的问题,但 codeigniter 仍然不允许文件类型

【问题讨论】:

  • 发生了什么你不想发生的事情?你有什么办法来解决它?
  • php 手册中有两种用于 svg 的 mime 类型,即 svg 和 svgz。我会尝试添加到我的配置 svgz
  • 我刚刚遇到了同样的问题。进一步调试显示,codeigniter 将 mime 类型识别为我的 svg 的 text/plain。由于这在 svg 下的 config/mimes.php 中不存在,因此在 mime_type 检查中失败。我认为问题在于错误识别 svg 的 mime 类型。

标签: php codeigniter svg


【解决方案1】:

在我的例子中,php 将文件识别为 image/svg

我刚刚添加到我的 config/mimes.php

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

【讨论】:

    猜你喜欢
    • 2020-03-05
    • 2018-01-23
    • 1970-01-01
    • 2018-09-13
    • 2011-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-03
    相关资源
    最近更新 更多