CodeIgniter Image and File Upload
public function insertblog()
{
$title = $this->input->post('title');
$author = $this->input->post('author');
$date = $this->input->post('date');
$description = $this->input->post('description');
$status = $this->input->post('status');
$images_count = count($_FILES['userfile']['name']);
$_FILES['image']['name'] = $_FILES['userfile']['name'];
$_FILES['image']['type'] = $_FILES['userfile']['type'];
$_FILES['image']['tmp_name'] = $_FILES['userfile']['tmp_name'];
$_FILES['image']['error'] = $_FILES['userfile']['error'];
$_FILES['image']['size'] = $_FILES['userfile']['size'];
$config['upload_path'] = 'uploads';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload('userfile')){
$data = array('upload_data' => $this->upload->data());
$img[] = $data['upload_data']['file_name'];
}
$product = array(
'title' => $title,
'author' => $author,
'date' => $date,
'description' => $description,
'status' => $status,
'image' => implode(",",$img),
);
if ($this->admin_blog_model->insertblog($product))
{
redirect('admin/all_blog');
}
else
{
redirect('admin/add_new_blog');
}
$this->admin_blog_model->insertblog($data);
$this->load->view('admin/edit_new_blog', $data);
redirect ('admin/add_new_blog');
}
0 comments:
Post a Comment
Thanks