Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove image from web root when data edit and update by cakephp

I write a edit function to update news's info, delete previous image from web root and insert new image:

code is below:

       if(unlink($data['News']['image_url']['tmp_name'], WWW_ROOT . 'media/' . $data['News']['image_url']['name'])) //delete image from root and database
            {
                echo 'image deleted.....';  //success message
            }

I can't delete old image and insert new image,how can i correct my function ?


1 Answers

Here your data can not find existing data. use this code

$data1 = $this->News->findById($newsid);
$this->request->data = $data1;
$directory = WWW_ROOT . 'media';
if(unlink($directory.DIRECTORY_SEPARATOR.$data1['News']['image_url']))  
{
    echo 'image deleted.....';  
}
like image 55
Lemon Kazi Avatar answered Feb 25 '26 06:02

Lemon Kazi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!