Hi Master,
I cant unlink or update my uploaded image. I can successfully upload image bt i cant use unlink function or Any body help me how can i remove / Update uploaded image.
Here is my Controller:
public function addProfileLogo() {
$data = array();
$errors = '';
if ($_FILES['logo_image']['name'] && $_FILES['logo_image']['size']) {
$result = $this->logoUpload('logo_image');
// here logo_image = table culm name.
if ($result) {
if ($result['file_name']) {
$data['logo_image'] = $result['file_name'];
if ($data['logo_image']->logo_image)
{
unlink($data['logo_image']->logo_image);
}
$data['user_id'] = $this->session->userdata('user_id');
$this->user_admin_model->saveProfilelogo($data); // saveProfilelogo = model fun name.
} else {
$errors = $result['error'];
}
}
}
if (($errors!="") ) {
$err['exception'] = "You do Upload correct Formet!";
$this->session->set_userdata($err);
}
redirect("user_admin_controller/editProfileLogo", 'refresh');
}
public function logoUpload($fieldName) {
$config['upload_path'] = 'image/instlogos/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['overwrite'] = FALSE;
$config['max_size'] = '200';
$config['max_width'] = '';
$config['max_height'] = '';
$this->load->library('Upload');
$this->upload->initialize($config);
if ($this->upload->do_upload($fieldName)) {
$data = $this->upload->data();
$fileName = $config['upload_path'] . $data['file_name'];
$return = array('file_name' => $fileName, 'error' => '');
return $return;
} else {
$err = '';
echo $this->upload->display_errors();
$return = array('file_name' => '', 'error' => $err);
return $return;
}
}
My Model is:
public function saveProfilelogo($data) {
$this->db->insert('tbl_profile_logo', $data);
return $this->db->affected_rows();
}
Image Edit/Remove Form View:
<form action="<?php echo base_url(); ?>user_admin_controller/addProfileLogo" enctype="multipart/form-data" method="post">
<input type="file" name="logo_image" required="1" accept="image/png, image/jpeg, image/jpg" class="span5"/>
<input type="submit" value="Edit Logo"/>
</form>
please help me..Thanks