I have an Upload model – contains images uploaded by the user.
Within the controller, I’m calling:
$this->Upload->delete($id);
Which works just fine to delete the record from the database, but I’d also like to delete the corresponding image file.
I’ve tried a lot of different things with different variables..etc, and found this link to a similar question, but – nothing seems to work – I can’t even get it to delete with any of these attempts:
//at the bottom of my Upload model
function afterDelete() {
//NONE OF THESE WORK - is this even being called?
unlink('/img/uploads/rest_logo.jpg');
unlink('app/webroot/img/uploads/rest_logo.jpg');
unlink('/app/webroot/img/uploads/rest_logo.jpg');
unlink('img/uploads/rest_logo.jpg');
unlink(WWW_ROOT . 'img/uploads/rest_logo.jpg');
unlink(WWW_ROOT . '/img/uploads/rest_logo.jpg');
return true;
}
Obviously I’ll want to change it to be a dynamic filename, but for now, I can’t even get it to delete the file when hard-coding all the different possible paths I can think of.
Is there a way to test what’s going on in this? Like an echo or… anything?
Any help or direction is greatly appreciated.
Detail about File Utility