【发布时间】:2018-05-19 12:40:33
【问题描述】:
当我尝试上传 MP4 电影文件时,我不断收到错误 The filetype you are attempting to upload is not allowed。
这是我的上传功能
public function upload_post() {
$config['upload_path'] = ROOT_DIR . $dataBasePath;
$config['allowed_types'] = 'avi|mov|mp4|jpeg|jpg|png';
$config['remove_spaces'] = true;
$config['max_size'] = '80000';
$config['encrypt_name'] = true;
$this->upload->initialize($config);
if ($this->upload->do_upload('userFile')) {
$uploadData = $this->upload->data();
if ($uploadData) {
$this->response([
'data' => $uploadData
], REST_Controller::HTTP_OK);
} else {
$this->response([
'status' => false,
'message' => 'failed'
], REST_Controller::HTTP_CONFLICT);
}
} else {
var_dump($_FILES);
die();
$this->response([
'status' => false,
'errors' => ['error' => $this->upload->display_errors()]
], REST_Controller::HTTP_CONFLICT);
}
}
当我上传一个文件和var_dump($_FILES)数据如果上传失败,这是结果
array (size=1)
'userFile' =>
array (size=5)
'name' => string '1-video.mp4' (length=11)
'type' => string '' (length=0)
'tmp_name' => string '' (length=0)
'error' => int 1
'size' => int 0
var_dump(get_mime_by_extension($_FILES['userFile']['name'])) 的结果如下
'video/mp4'
我还检查了我的 mimes.php 文件,我有完整的
'mp4' => array('video/mp4', 'application/octet-stream'),
我不知道我还应该做什么或检查才能成功上传文件?上传图片工作正常。 如果您需要任何其他信息,请告诉我,我会提供。谢谢
【问题讨论】:
-
你可以试试 $config['allowed_types'] = "*";
-
如果我这样做,然后我得到另一个错误:尝试将上传的文件移动到最终目的地时遇到问题
-
使用 FCPATH 而不是 ROOT_DIR
-
文件有多大,你的 post_max_size 和 upload_max_filesize 是多少?显示定义 ROOT_DIR 的代码
标签: php codeigniter codeigniter-3