Monday 15 August 2011

php - Variable + Wildcard image removal -



php - Variable + Wildcard image removal -

i want create piece of code remove images based on set parameters , wildcard.

the number of images , naming vary, though first 2 parameters remain constant.

// illustration of images deleted / removed.

/images/1-50-variablename-a.jpg /images/1-50-variablename-b.jpg /images/1-50-variablename-c.jpg /images/1-50-variablename-d.jpg /images/1-50-variablename-e.jpg

essentially after loop create happen though not sure on best logic create happen.

$menuid = "1"; $imageid = "50" $filename = "images/".$menuid."-".$imageid."-*.jpg"; if (file_exists ($filename)) { unlink ($filename);

}

you can utilize php glob function (http://php.net/manual/fr/function.glob.php). feed pattern (it supports wildcards) , iterate on result , unlink each file.

hope helped

php image

No comments:

Post a Comment