First add the next function to your file:
function delete_images_by_refnum($image_folder, $ref_num)
{
$d = opendir($image_folder);'
if(!is_resource($d)) return;
while($f = readdir($d))
{
if(substr($f, 0, strlen($ref_num)+1) == $ref_num + '_')
unlink ($image_folder.'/'.$f);
}
}
Secondly edit the code you quotes in your last post to call the function:
if ($row = mysql_fetch_array($PropertiesResult))
{
$ref_num = $row['property_ref_num'];
delete_images_by_refnum(dirname(__FILE__).'/myimagefolder', $ref_num);
You have to change the first argument to state the correct foldername offcourse. You have to provide a relative link to the file this code is in. So when your code is in lib/delete.php and your images are in img/ the command would be:
delete_images_by_refnum(dirname(__FILE__).'/../img', $ref_num);