【发布时间】:2017-01-01 07:25:55
【问题描述】:
如何使用上传库在codeigniter中上传php或html文件?我有控制器在上传 jpg、gif、png 文件时工作正常,但它不会上传带有 php、html 或 sql 扩展名的文件。
这是我的控制器
public function ipload()
{
$this->load->helper('url');
$this->load->model('m_company');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'php|html|txt';
$config['max_size'] = 2048;
$config['max_width'] = 0;
$config['max_height'] = 0;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('userfile'))
{
$data = array('error' => $this->upload->display_errors());
}
else
{
$this->upload->do_upload('userfile');
$data = array('upload_data' => $this->upload->data());
$filen = $this->upload->data('file_name');
$this->m_company->set_doc($filen);
}
echo json_encode($data);
}
当允许的文件是 jpg gif png 时一切正常
【问题讨论】:
-
您是否尝试将 allowed_types 设置为数组?它是管道字符串的替代品,不应该有所作为,但上传库可能存在问题。另外,它适用于哪个版本的 CodeIgniter?
-
我现在尝试设置为数组,它仅适用于 jpg,不适用于 php、html、txt ...文件。 CI_version 为 3.0.6。我没有提到 do_upload 没有抛出错误消息也没有上传数据
标签: codeigniter