File Upload Using Blob and Folder in Codeigniter
Controller:-
if(!empty($_FILES['product_image']['name'])){
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['file_name'] = $_FILES['product_image']['name'];
//Load upload library and initialize configuration
$this->load->library('upload',$config);
$this->upload->initialize($config);
if($this->upload->do_upload('product_image')){
$uploadData = $this->upload->data();
//print_r($uploadData['full_path']);die;
$product_image = file_get_contents($uploadData['full_path']);
}else{
$product_image = '';
}
}else{
$product_image = '';
}
View:
Add in Form
<form role="form" class="form" action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="product_image">Product Image</label>
<input type="file" class="form-control" name="product_image" placeholder="Enter title" />
</div>
if(!empty($_FILES['product_image']['name'])){
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['file_name'] = $_FILES['product_image']['name'];
//Load upload library and initialize configuration
$this->load->library('upload',$config);
$this->upload->initialize($config);
if($this->upload->do_upload('product_image')){
$uploadData = $this->upload->data();
//print_r($uploadData['full_path']);die;
$product_image = file_get_contents($uploadData['full_path']);
}else{
$product_image = '';
}
}else{
$product_image = '';
}
View:
Add in Form
<form role="form" class="form" action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="product_image">Product Image</label>
<input type="file" class="form-control" name="product_image" placeholder="Enter title" />
</div>
Comments
Post a Comment