Controller:
public function do_register()
{
$path = $_FILES['image']['name'];
$imgext=strtolower(strrchr($path,'.'));
$imgname= $this->generateRandomString().$imgext;
if($path!='')
{
$im= $this->config->item('base_url').'/uploads'.'/'.$imgname;
$x=$this->do_upload($imgname);
$data['img']=$im;
}
$this->search_model->register_user($data);
$this->load->view('register_view');
}
function generateRandomString()
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$randomString = '';
for ($i = 0; $i < 8; $i++)
{
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
function do_upload($img)
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '575000';
$config['file_name'] = $img;
$this->load->library('upload',$config);
if ( ! $this->upload->do_upload('image'))
{
$error = array('error' => $this->upload->display_errors());
}
else
{
$data = array('upload_data' => $this->upload->data());
return $data;
}
return;
}
This is the controller for image upload.When i select the image foe uploading the image is not displayed while i selecting the filename? what is the solution for this? How to display the image after selecting the filename? Please provide a code for this?