Hi Guys,
I have a database and one of the columns contains links to images stored on my server. I have a cron job that filters through the database and deletes rows that are old. When a row is deleted, I also want to delete whatever image was stored in the 'image' filed of that row. I have the following code where the row is deleting fine, but the image is not getting deleted. Someone told me the image path used in unlink has to be relative which is why I am using substr()
I have a database and one of the columns contains links to images stored on my server. I have a cron job that filters through the database and deletes rows that are old. When a row is deleted, I also want to delete whatever image was stored in the 'image' filed of that row. I have the following code where the row is deleting fine, but the image is not getting deleted. Someone told me the image path used in unlink has to be relative which is why I am using substr()
PHP Code:
//AN EXAMPLE OF WHAT WOULD BE IN THE IMAGE FIELD: http://www.dealbind.com/images/dealimages/6369.jpg
$findold = "SELECT * FROM deals WHERE TIMESTAMPDIFF(HOUR, `insertdate`, NOW() ) > 2";
$execute = mysql_query($findold);
while($row = mysql_fetch_array($execute)){
$image = $row['image'];
$imagesub = substr($image,0,23);
if($imagesub == "http://www.dealbind.com"){
unlink(substr($image,23));
}
$dealid = $row['dealid'];
$delete = "DELETE FROM deals WHERE dealid = '$dealid'";
$executedelete = mysql_query($delete);
}
Comment