【问题标题】:Codeigniter - File Upload and GoDaddyCodeigniter - 文件上传和 GoDaddy
【发布时间】:2014-11-21 13:20:18
【问题描述】:

由于某种原因,这段代码可以在我的本地机器上运行,但是当我将它上传到我的 GoDaddy 服务器时它不起作用,它告诉我“不允许您尝试上传的文件类型。”。只有当我尝试上传 csv 和 xlsx 文件时才会发生这种情况,png 和 jpgs 工作没有问题。

    $filename = "classlist_".date("YmdHis").".csv";
    $config['upload_path'] = APPPATH. '../uploads/';
    $config['allowed_types'] = 'xlsx|xls|jpg|png|csv';
    $config['max_size'] = '1000';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';

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

    if (!$this->upload->do_upload())
    {
        print_r($this->upload);

        echo "error<br/>".$this->upload->display_errors();
        exit;
    }
    else
    {
        exit;

【问题讨论】:

  • 有什么错误吗?有什么通知吗?
  • 您在 GoDaddy 服务器中使用的是哪个 Codeignitor 版本?
  • @Naruto 没有通知或错误,除了 CI 输出的那个
  • @Vidhi 我使用的是 2.1.4 版
  • 检查文件权限和上传文件夹权限。

标签: php codeigniter file-upload


【解决方案1】:

这是特定文件类型的服务器配置问题。这意味着在mimes.php 文件的$mimes 变量中找不到服务器为xlsx 提供的文件类型。文件mimes.php 位于application/config/mimes.php。只需打印 $_FILES 变量并将您在 $mimes 变量中看到的 mime 添加。

另一种方法是在 .htaccess 文件中强制使用这些 mime:

AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
AddType application/excel xls
AddType text/x-comma-separated-values csv

【讨论】:

  • print_r($_FILES); 在文件$this-&gt;upload-&gt;do_upload() 之后打印什么?
  • 当然它没有工作,因为你必须指定哑剧。这是一个例子,不是一个工作代码!
  • 是的,我知道它的代码不起作用。我使用 print_r($this->upload); 时打印的 mime 类型;
  • mimetype 是什么?
  • [xlsx] => 数组([0] => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet [1] => application/zip)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-06
  • 2011-10-19
  • 2011-11-06
相关资源
最近更新 更多