Hey,
I am building a classifieds section on my site and need some help with the following.
Listings are added for 6 months. After this time the listing is not shown on the site but the information is stored for another 7 days incase they want to extend their listing. After this time the listing is deleted from the site.
Heres my problem.
I need to automatically delete the old listing and the images. I can delete the listing and the image from the database, but cant delete the folder that contains the images. This is what i tried:
$result = mysql_query("SELECT i_id FROM classified_other WHERE DATE_ADD(i_expires, INTERVAL 7 DAY) < NOW()")
or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$dir = "images/classified/other/".$row['i_id']."";
$id = $row['i_id'];
function rmdirr($dir) {
if($objs = glob($dir."/*")){
foreach($objs as $obj) {
is_dir($obj)? rmdirr($obj) : unlink($obj);
}
}
rmdir($dir);
}
$delete_img = "DELETE FROM classified_img WHERE i_id = $id";
mysql_query($delete_img, $tidp_main) or die (mysql_error());
$delete_listing = "DELETE FROM classified_other WHERE i_id = $id";
mysql_query($delete_listing, $tidp_main) or die (mysql_error());
}
The folder is created when they upload an image and the folder name is the listing id. So listing id 10 will be here: images/classified/other/10
also inside this folder a thumbnail folder is created which also needs deleting:
images/classified/other/10
images/classified/other/10/thumbnails
Any help would be great!
Thanks,
Danny Lewin