How to unlink multiple files in codeigniter?
I have to delete records from database.
delete records works .
what i want, after deleting records also files should get delete form directory(/uploads/deals/)
My scripts is below:

public function delete($merchant_deals_id)
       $deal = $this->admin_deal_model->get_single_deal($merchant_deals_id);
       $path = './uploads/deals/';
       $image1 = $path.$deal['deal_images1'];
       $image2 = $path.$deal['deal_images2'];
       $image3 = $path.$deal['deal_images3'];
       $files = array($image1, $image2, $image3);     

       $data = array('deals' => $this->admin_deal_model->delete());

        $this->session->set_flashdata('deals', '<p>Deals successfully deleted!</p>');

        redirect('admin/admin_merchant_deal', $data);


sorry for my terrible english

Assuming that $path is relative to the CodeIgniter main index.php file, then change path to:

$path = FCPATH . 'uploads/path/';

The constant FCPATH is defined in the index.php file. Then simply loop the $files array against unlink():

array_map('unlink', $files);

And that's all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.