I am using the following function in my model:
function uploadsinglepicture($uploadpath){
$config['upload_path'] =$uploadpath;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '';
$config['max_width'] = '';
$config['max_height'] = '';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
print_r($error);
if($this->input->post('id') == ''){
$insertion['image'] = '';
}
//$this->load->view('upload_form', $error);
}
else{
$data = array('upload_data' => $this->upload->data());
$insertion['image'] = $data['upload_data']['file_name'];
}
$image = $insertion['image'];
return $image;
}
This is how I access the function in controller:
if(!empty($this->input->post())){
$path= base_url().'assets/front/img';
$this->general->uploadsinglepicture($path);
redirect(base_url().'admin/home/index/sliderupated');
}
but the error I get is:
Array ( [error] => The upload path does not appear to be valid. )
If I print $path
, this is what I get
http://localhost/site/assets/front/img/
and that opens in the browser as real path. My code in view is as below
<form method="post" enctype="multipart/form-data" action ="<?=base_url()?>admin/home/index" >
<label>Upload Picture </label>
<input type='file' name='userfile' />
<input type="hidden" name="updateimage">
<input type="submit" class="btn btn-primary pull-right" />
</form>
How can I fix the error?