CodeIgniter:“您尝试上传的文件类型不被允许”。 [英] CodeIgniter: "The filetype you are attempting to upload is not allowed."
问题描述
我遇到了一个非常奇怪的上传问题。以下是相关的视图文件:
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
$ c> 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 dumps:
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
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
。 Hope this help =)
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论坛的主题
- Firefox中的计算机类型损坏
- 绕过IE的MIME类型修改
- CodeIgniter forum's thread
- Mimetype corruption in Firefox
- Getting around IE’s MIME type mangling
这篇关于CodeIgniter:“您尝试上传的文件类型不被允许”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!