How to delete a file via PHP?
$files = [
'./first.jpg',
'./second.jpg',
'./third.jpg'
];
foreach ($files as $file) {
if (file_exists($file)) {
unlink($file);
} else {
// File not found.
}
}
The following should help
realpath
— Returns canonicalized absolute pathnameis_writable
— Tells whether the filename is writableunlink
— Deletes a file
Run your filepath through realpath, then check if the returned path is writable and if so, unlink it.