【问题标题】:CodeIgniter upload txt doc - The filetype you are attempting to upload is not allowedCodeIgniter 上传 txt 文档 - 不允许您尝试上传的文件类型
【发布时间】:2014-12-30 01:04:33
【问题描述】:

CodeIngiter 版本:2.2

我正在开发一个 PHP API,我正在尝试上传一个文件。代码是:

    $config['upload_path'] = $path;
    $config['allowed_types'] = 'gif|jpg|png|jpeg|jpe|pdf|doc|docx|rtf|text|txt';
    $config['max_size'] = '4096';
    $config['max_width'] = '1024';
    $config['max_height'] = '1024';
    $config['encrypt_name'] = true;

    $CI =& get_instance();
    $CI->load->library('upload', $config);

    $CI->upload->do_upload("file")

它适用于图像文件和 pdf 文件,但是当我尝试上传 .txt 或 .doc 文件时出现错误:不允许您尝试上传的文件类型

我正在使用 Postman 工具(表单数据模式)进行测试。我检查了 mimes.php 文件,它似乎是正确的。

谁能帮助我?谢谢

【问题讨论】:

  • Postman 中使用x-www-form-urlencoded 提交表单
  • 如何使用“x-www-form-urlencoded”提交文件?它不是多部分的,不是吗?

标签: codeigniter file-upload mime-types


【解决方案1】:

您是否检查了您的服务器实际接收的文件类型?

var_dump($this->upload->data());

然后你可以检查你的哑剧是否真的正确。

希望对你有帮助

@edit

您似乎正在尝试上传一个空文件。如果您需要您的应用接受甚至是空文件,您可以在 mimes.php(行 'txt')中执行此操作:

'txt'   =>  array('text/plain', 'application/x-empty'),

【讨论】:

  • 嗯,我得到:array(14) { ["file_name"]=> string(7) "doc.txt" ["file_type"]=> string(19) "application/x-空" ["raw_name"]=> string(3) "doc" ["orig_name"]=> string(0) "" ["client_name"]=> string(7) "doc.txt" ["file_ext"] => 字符串(4)“.txt”
  • 是的,我正在使用空文件进行测试!我学到了一些新东西。谢谢加布里埃尔
  • 谢谢,我试过var_dump数据,上传png图片时显示image/jpeg,无论如何通过在mimes.php中添加image/jpeg解决了这个问题,在png下
猜你喜欢
  • 2017-08-18
  • 2012-04-06
  • 2011-11-21
  • 2011-06-08
  • 2012-04-22
  • 1970-01-01
  • 1970-01-01
  • 2023-04-07
  • 2019-02-27
相关资源
最近更新 更多