I have a problem like this in my website. I have created a option to upload a image. I have search for so many times but i didn't get a solution.
This the code in my view file.
<div class="form-group">
<label for="exampleFormControlFile1"><p>4 : Media * :</p></label>
<p> <input type="file" name="file_name">
</div>
This the code in my controller.
public function create(){
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'jpg|png|jpeg';
$this->load->library('upload', $config);
$this->upload->do_upload('file_name');
$file_name=$this->upload->data();
$data=array(
'institute'=>$this->input->post('institute'),
'category'=>$this->input->post('category'),
'content'=>$this->input->post('content'),
'relavent_authority'=>$this->input->post('relavent_authority'),
'multimedia'=>$file_name['file_name'],
'created'=>date("Y-m-d H:i:s"),
);
$data['id']=$this->Question_model->add_data($data);
$data['authority'] = $this->Question_model->getAuthority();
if($this->input->post('share')=="yes"){
$this->load->view('header',$data);
$this->load->view('questions/share',$data['id']);
$this->load->view('footer');
}
}
For the uploaded file i have create a folder called uploads. But uploading is not working. It is not giving error either. What is the problem with this code?
Try this on your form tag by adding "enctype"
<form action="upload.php" method="post" enctype="multipart/form-data">
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments