【发布时间】:2019-08-14 20:13:49
【问题描述】:
我正在创建一个需要用户提交文件的页面,它还将文件名与其他一些数据一起保存在数据库中。
我尝试使用$_FILES 超全局手动配置允许的文件属性,但由于某种原因没有上传,然后我决定使用 CI 的文件上传类,它更简单。我遇到了同样的问题,但代码更容易使用:
if (isset($_POST['submit'])) {
$data = $this->input->post('input');
$this->security->xss_clean($data);
$config['upload_path'] = './photos/';
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = '1000000';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('file')) {
$error = array('error' => $this->upload->display_errors());
}
else {
//Form validation and insert of filename as a string
}
}
我希望它返回 true 并将新记录插入数据库并保存文件,但是这些都不会发生。顺便说一句,我使用$_FILES["file"]["name"] 将文件名保存在数据库中,我认为还有另一种方法可以做到这一点?
【问题讨论】:
标签: php file codeigniter