[英]Codeigniter File upload is not working after updating to latest version.
现在,当我上传任何文件后,将项目文件更新为Codeigniter的最新版本后,它将返回此错误:
不允许您尝试上传的文件类型。
代码如下:
public function test_upload(){
$config = array(
'upload_path' => './assets/upload_test',
'allowed_types' => 'gif|jpg|png|jpeg|pdf',
'max_size' => '2048',
);
if($_FILES['file']['name'] != '')
{
$image = 'file';
$upload_data = $this->do_upload($image, $config);
if($upload_data['condition']=='error')
{
echo json_encode(array('condition'=>'error', 'message'=>$upload_data['error'].' (User image)')); exit;
}else{
$profile_picture['file'] = $upload_data['upload_data']['file_name'];
}
}
print_r($profile_picture);exit;
}
public function do_upload($image, $config)
{
$this->load->library('upload');
$this->upload->initialize($config);
if ( ! $this->upload->do_upload($image))
{
$error = array('condition'=>'error', 'error' => $this->upload->display_errors());
return $error;
}
else
{
$data = array('condition'=>'success', 'upload_data' => $this->upload->data());
return $data;
}
}
搜索很多,但是找不到任何好的解决方案。 感谢大家的回应。
我从Google找到了答案,但我会花很多时间。 只需更改此行:
'allowed_types'=>'gif | jpg | png | jpeg | pdf'
将此行替换为:
'allowed_types'=>'*'
我的问题解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.