CodeIgniter: “The filetype you are attempting to u

2019-01-04 03:27发布

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>

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());
    }
}

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\tmp\php2333.tmp' (length=23)
      'error' => int 0
      'size' => int 83914

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')

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?

UPDATE 1:

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?

10条回答
姐就是有狂的资本
2楼-- · 2019-01-04 03:39

Change IN application\config\Mimes.php

查看更多
来,给爷笑一个
3楼-- · 2019-01-04 03:42

Answer for to Upload .doc file in CodeIgniter

Change this

'doc'   =>  'application/msword',

With this on line no 95 (application/config/mimes.php file)

'doc'   =>  array('application/vnd.ms-word','application/msword'),
查看更多
Melony?
4楼-- · 2019-01-04 03:43

This is actually a bug in the core.. I upgraded to latest version of CI and the bug disappeared.

查看更多
beautiful°
5楼-- · 2019-01-04 03:45

You are using Firefox, aren't you?

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

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

Change that line to:

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

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 =)

Similar answer here

Some links:

查看更多
叛逆
6楼-- · 2019-01-04 03:45

did you try using mime types instead of extensions in $config['allowed_types']?

write it like this

$config["allowed_types"] = "video/x-msvideo|image/jpeg|video/mpeg|video/x-ms-wmv";
查看更多
走好不送
7楼-- · 2019-01-04 03:45

Check your mimes.php file in application/config. It should return an array of mime types e.g return $mimes; at end of file or return array(..... in start of mimes array.

查看更多
登录 后发表回答