gpt4 book ai didi

php - 代码点火器: "The filetype you are attempting to upload is not allowed."

转载 作者:IT王子 更新时间:2023-10-29 01:23:49 26 4
gpt4 key购买 nike

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

<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 Controller 的 upload() 方法:

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 转储:

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 具有以下内容:

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

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

任何想法可能是错误的?

更新 1:

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

最佳答案

您正在使用 Firefox,对吗?

您可以尝试查看 system/libraries/Upload.php 第 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。希望这有帮助 =)

相似答案here

一些链接:

关于php - 代码点火器: "The filetype you are attempting to upload is not allowed.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9815208/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com