How to remove image from web root when editing and updating cakephp data
I am writing an edit function to update news information, remove the previous image from the web root, and insert a new image:
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 cannot delete the old image and insert the new image, how can I fix my function?
+3
user4101645
source
to share
2 answers
Pass the path to the file as the first argument unlink()
:
unlink(WWW_ROOT . 'media/' . $data['News']['image_url']['name'] . '/' . $data['News']['image_url']['tmp_name']);
Also make sure you have the appropriate permissions to perform this operation in the directory containing the image.
0
source to share