Question

How can i delete image files from uploaded folder in codeigniter from delete button?? Can any one guide me ??? Here is my controller that upload image files

private function upload() {
    $config['upload_path'] = 'assets/uploads/orginal/';
    $config['allowed_types'] = 'gif|jpg|png|jpeg|x-png';
    $config['max_size'] = '500';
    $config['max_width'] = '1600';
    $config['max_height'] = '1200';
    $config['remove_spaces'] = TRUE;
    $this->load->library('upload', $config);
    if ($this->upload->do_upload()) {
        $img = $this->upload->data();
        // create thumbnail
        $new_image = 'assets/uploads/thumbs/' . $img['file_name'];

        $c_img_lib = array(
            'image_library' => 'gd2',
            'source_image' => $img['full_path'],
            'maintain_ratio' => TRUE,
            'width' => 100,
            'height' => 100,
            'new_image' => $new_image
        );

        $this->load->library('image_lib', $c_img_lib);
        $this->image_lib->resize();
    } else {
        $this->data['error'] = $this->upload->display_errors();
    }
}
Was it helpful?

Solution

Use the unlink() function:

unlink($new_image);

http://pt1.php.net/manual/en/function.unlink.php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top