How to upload images and videos in two different folders using CodeIgniter 3?
I have done only images. Please guide me through videos. I want to upload image and videos in two different folders.
My Controller, Model and View
class Blog extends CI_Contrller{
public function create_blog(){
// Check Login
if(!$this->session->userdata('logged_in')){
redirect('blogs/login');
}
$data['title'] = 'Create Blog';
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('content', 'Content', 'required');
if($this->form_validation->run() === FALSE){
$this->load->view('templates/header');
$this->load->view('blog/create_blog', $data);
$this->load->view('templates/footer');
} else {
// Upload Image
$path = './assets/uploads/blogs/images';
$config['upload_path'] = $path;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 15000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if(!$this->upload->do_upload()){
$this->session->set_flashdata('file_error', $this->upload->display_errors());
$post_image = 'noimage.jpg';
redirect('blog/create_blog');
}else{
$data = array('upload_data' => $this->upload->data());
$post_image = $_FILES['userfile']['name'];
}
$this->M_blog->create_blog($post_image);
redirect('blog/view');
}
}
}
Model
// Model Begins here
public function create_blog($post_image){
$slug = url_title($this->input->post('title'));
$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'content' => $this->input->post('content'),
'image' => $post_image
);
return $this->db->insert('events', $data);
}
View
// View begins here
<div class="container"><br>
<h2><?= $title ?></h2>
<?php echo form_open_multipart('blog/create_blog'); ?>
<?php echo validation_errors(); ?>
<?php echo $this->session->flashdata('file_error'); ?>
<div class="form-group">
<label>Title</label>
<input type="text" class="form-control" name="title"
placeholder="Add Title">
</div>
<div class="form-group">
<label>Body</label>
<textarea class="form-control" id="editor1" name="content"
placeholder="Add Body"></textarea>
</div>
<div class="form-group">
<label>Upload Image</label>
<input type="file" name="userfile" id="userfile" size="20" />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>