我正在尝试将图像上传到文件路径并将该路径插入到数据库中。但是,上传总是显示错误您没有选择要上传的文件..即使我做了。
这是我的观点
<form action="<?= site_url('profile/profile_submit')?>" method="post" enctype="multipart/form-data">
<input type="file" class="image-upload" accept="image/*" name="profilePic" id="profilePic"/>
</form>
控制器
$config['upload_path'] = 'assets/img/profile_img/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['overwrite'] = TRUE;
$config['max_size'] = "2048000";
$config['max_height'] = "768";
$config['max_width'] = "1024";
$this->load->library('upload', $config);
if ($this->upload->do_upload('profilePic')){
$data = $this->upload->data();
$picture = array(
'photoPath' => $this->upload->data('full_path').$data['file_name']
);
}
else{
echo $this->upload->display_errors();
}
$this->profile_model->submit_profile($picture);
模型
function submit_profile($picture){
$this->db->insert('tbl_st_picture', $picture);
}
更改您的上传代码如下。不要$this->input->post()
用于获取文件数据。还要确保您已enctype="multipart/form-data"
在表单中添加
if ($this->upload->do_upload('profilePic')){
$data = $this->upload->data();
$picture = array(
'photoPath' => $this->upload->data('full_path').$data['file_name'],
);
}
else{
echo $this->upload->display_errors();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句