I use the codeigniter framework. My image is stored in the bdd from my form but it does not show up. I suppose an encoding problem, when I put the form open multipart I have an error message that my image is NULL
le model
public function addPost(Articles_model $data){
$this->load->helper('form');
$data = array(
'article_title' =>$data->getTitle(),
'article_img' =>$this->input->post('article_img'),
'article_content' =>$data->getContent(),
'article_createdate' =>$data->getCreateDate(),
);
return $this->db->insert('articles',$data);
}
le controller
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = '*';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
the forms:
$data['form_open'] = form_open("/paging/addPost");//<form action="#" name="formCreateAccount" method="post" >
$data['fieldset_user'] = form_fieldset($this->lang->line("users_infos")); //<fieldset><legend>Informations utilisateur</legend>
$data['form_userid'] = form_hidden("id", $this->input->post('id'));//<input type="hidden" name="user_id" value="<?php echo isset($_POST['user_id'])?$_POST['user_id']:''
// label + input titre
$data['label_titre'] = form_label($this->lang->line("labeltitre"), 'titre'); //<label for="name">Nom</label>
$data['form_titre'] = form_input('article_title', $this->input->post('article_title'), 'id="titre"');//<input required type="text" name="user_name" id="name" value="<?php echo isset($_POST['user_name'])?$_POST['user_name']:'';
// label + input image
$data['label_img'] = form_label($this->lang->line("article_imgs"), 'file'); //<label for="firstname">Prénom</label>
$data['form_img'] = form_upload('article_img', $this->input->post('article_img'), 'id="img"');//<input required type="text" name="user_firstname" id="firstname" value="<?php echo isset($_POST['user_firstname'])?$_POST['user_firstname']:'';