i have admin system adds profile pages dynamically - , part of adds images directory. when add images have name format 12_1.jpg, 12_2.jpg, 32_1.jpg, 32_9.jpg number before underscore id $cid
, number after underscore image number.
i'm trying find way list images on edit-images.php page option delete them (maybe link next image name, or way better).
here code find images need have option of deleting:
if ($handle = opendir('../images/company')) { while (false !== ($entry = readdir($handle))) { if (substr(basename($entry), 0, 2) == $cid) { echo $entry . "<br>"; } } closedir($handle); }
how go deleting specified images here? appreciated.
why scanning directory file? can check if file exists , delete instead. example:
$files = glob("../images/company/$cid_*.jpg"); foreach($files $file) { if(file_exists($file)) unlink($file); }
this unlink files in ../images/company
name starting 123_
example , ending in .jpg
(you can provide more extensions using glob_brace
parameter)
Comments
Post a Comment