我正在尝试使用codeigniter
为用户上传个人资料图片。将图像发布到文件系统中的语法还可以,我需要知道如何为每个特定图像添加userid
。我尝试使用下面的代码,但它返回0作为用户ID
function seekerImageStore()
{
if(isset($_FILES["image_file"]["name"]))
{ $user = $this->session->userdata('myuserid_vipajijobs');
$config['upload_path'] = './uploads/seekerimages';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$this->load->library('upload', $config);
if(!$this->upload->do_upload('image_file'))
{
$error = $this->upload->display_errors();
echo json_encode(array('msg' => $error, 'success' => false));
}
else
{ $user = $this->session->userdata('myuserid_vipajijobs');
$data = $this->upload->data();
$insert['name'] = $data['file_name'];
$this->db->insert('images',$insert);
$pic=$this->input->post('image_file');
$this->db->insert('images',['user'=>$user,'name'=>$pic]);
$getId = $this->db->insert_id();
$arr = array('msg' => 'Image has not uploaded successfully', 'success' => false);
if($getId){
$arr = array('msg' => 'Image has been uploaded successfully', 'success' => true);
}
}
}