CodeIgniter:“不允许您尝试上传的文件类型." [英] CodeIgniter: "The filetype you are attempting to upload is not allowed."

查看:37
本文介绍了CodeIgniter:“不允许您尝试上传的文件类型."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个非常奇怪的上传问题.这是相关的视图文件:

I'm experiencing a very odd upload problem. Here's the relevant view file:

<form action="http://localhost/index.php/temp/upload/" method="post" enctype="multipart/form-data">
    <fieldset>
        <input type="file" name="userfile"/>
        <input type="submit" value="Upload"/>
    </fieldset>
</form>

这是我的 temp 控制器的 upload() 方法:

And here's my temp controller's upload() method:

public function upload()
{
    $config['upload_path']   = FCPATH . 'uploads' . DIRECTORY_SEPARATOR;
    assert(file_exists($config['upload_path']) === TRUE);
    $config['allowed_types'] = 'avi|mpg|mpeg|wmv|jpg';
    $config['max_size']      = '0';

    $this->load->library('upload', $config);
    if ($this->upload->do_upload('userfile') === FALSE)
    {
        // Some error occured
        var_dump($this->upload->display_errors('', ''));
        var_dump($_FILES);
    }
    else
    {
        // Upload successful
        var_dump($this->upload->data());
    }
}

当我上传 AVI 视频时,一切正常.例如,当我上传 WMV 视频时,我得到以下 var 转储:

When I upload an AVI video, everything works fine. When I upload, say, a WMV video, I get the following var dumps:

string 'The filetype you are attempting to upload is not allowed.' (length=57)

array
  'userfile' => 
    array
      'name' => string 'wmv.wmv' (length=7)
      'type' => string 'video/x-ms-wmv' (length=14)
      'tmp_name' => string 'C:wamp	mpphp2333.tmp' (length=23)
      'error' => int 0
      'size' => int 83914

wmv"扩展名被解释为 MIME 类型:video/x-ms-wmv.这应该没问题,因为我的 config/mimes.php 有以下内容:

The "wmv" extension is being interpreted as the MIME type: video/x-ms-wmv. This should be fine since my config/mimes.php has the following:

'wmv' =>  array('video/x-ms-wmv', 'audio/x-ms-wmv')

当我尝试上传其他文件时也是类似的情况.到目前为止,唯一似乎有效的是我的测试 AVI 视频.

It's a similar situation when I try uploading other files. So far, the only one that seems to work is my test AVI video.

有什么想法可能出问题了吗?

Any ideas what might be wrong?

更新 1:

我的一台机器,只能上传 AVI.在另一个开发人员的机器上,没有文件上传.在另一台开发人员的机器上,所有支持的文件都上传.这些是浏览器还是服务器问题?

One my machine, only AVI uploads. On another developer's machine, no files upload. On yet another developer's machine, all supported files upload. Are these browser or server issues?

推荐答案

您正在使用 Firefox,对吗?

You are using Firefox, aren't you?

您可以尝试查看 system/libraries/Upload.php 第 199 行:

You could try looking at system/libraries/Upload.php line 199:

$this->_file_mime_type($_FILES[$field]);

将该行更改为:

$this->_file_mime_type($_FILES[$field]); var_dump($this->file_type); die();

然后上传您的 .wmv 文件.它会显示类似 application/octet-stream 之类的东西.将其添加到您的 mimes.php.希望这会有所帮助 =)

Then do upload your .wmv file. It would show something like application/octet-stream or whatever. Add that to your mimes.php. Hope this help =)

类似的答案这里

一些链接:

这篇关于CodeIgniter:“不允许您尝试上传的文件类型."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆