【问题标题】:Uploading zip and rar file not working in codeigniter上传 zip 和 rar 文件在 codeigniter 中不起作用
【发布时间】:2013-12-16 12:16:53
【问题描述】:

我为允许的类型创建的设置:

  $config['allowed_types'] = 'doc|docx|pdf|xls|xlsx|rtf|txt|rar|zip';

在我的 mine.php 中

  'zip' =>  array('application/x-zip', 'application/zip', 'application/x-zip-compressed','application/force-download'),
  'rar' =>  array('application/x-rar', 'application/rar','application/x-rar-compressed','application/force-download'),

这就是我配置的所有内容,但是当我进行 zip 或 rar 上传时,它会显示错误“不允许您尝试上传的文件类型。”

请帮助任何人..提前致谢..

【问题讨论】:

    标签: php codeigniter file-upload


    【解决方案1】:

    我已将 zip 和 rar 的 mime.php 配置替换为:

     'zip'  =>  array('application/x-zip', 'application/zip', 'application/x-zip-compressed','application/force-download','application/octet-stream'),
     'rar'  =>  array('application/x-rar', 'application/rar','application/x-rar-compressed','application/force-download','application/octet-stream'),
    

    我刚刚在末尾添加了application/octet-stream.. 对于这两种类型,现在我可以上传 zip 和 rar...:) 现在我很高兴

    【讨论】:

      【解决方案2】:

      这是检查 MIME 类型的最佳方法。

      在 codeigniter 框架中打开 system/libraries/upload.php。检查下面的评论。您将获得准确的 MIME 类型,并在 mimes.php 文件中包含相同的 MIME 类型。

      // Set the uploaded data as class variables
              $this->file_temp = $_FILES[$field]['tmp_name'];
              $this->file_size = $_FILES[$field]['size'];
              $this->_file_mime_type($_FILES[$field]);
              $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $this->file_type);
              $this->file_type = strtolower(trim(stripslashes($this->file_type), '"'));
              $this->file_name = $this->_prep_filename($_FILES[$field]['name']);
              $this->file_ext = $this->get_extension($this->file_name);
              $this->client_name = $this->file_name;
              //var_dump($this->file_type); Added by pratikn to check mime type
              //exit();
              // Is the file type allowed to be uploaded?
              if (!$this->is_allowed_filetype()) {
                  $this->set_error('upload_invalid_filetype');
                  return FALSE;
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-09-26
        • 2023-04-11
        • 1970-01-01
        • 2013-03-17
        • 2013-12-09
        • 2018-02-19
        • 1970-01-01
        相关资源
        最近更新 更多