jcstanley Posted January 26, 2007 Share Posted January 26, 2007 HiI currently have a php script which allows a user to do the following:A titleA descriptionUpload a picture.The picture gets stored in a folder called /pictures The mysql table has the following fields:titledescriptionpictureThe link to a picture gets stored in the picture field (eg. /pictures/image1.jpg)This all works fine until it comes to deleting. The delete query will delete the entry in the table, but obviously not the actual uploaded picture in the /pictures folder. Eventually the /pictures folder will get full of images that are no longer used.Is there anyway these pictures can be deleted at the same time as the data in the database?Thanks Link to comment https://forums.phpfreaks.com/topic/35786-deleting-a-file/ Share on other sites More sharing options...
Gruzin Posted January 26, 2007 Share Posted January 26, 2007 Try something like this:[code]$sql = mysql_query("SELECT * FROM archives WHERE date='$id'");while($row = mysql_fetch_array($sql)){$file = "uploads/".$row['link'];unlink($file);}$del = mysql_query("DELETE FROM archives WHERE date='$id'");[/code]Regards,George Link to comment https://forums.phpfreaks.com/topic/35786-deleting-a-file/#findComment-169579 Share on other sites More sharing options...
jcstanley Posted January 26, 2007 Author Share Posted January 26, 2007 Thank YouThat works perfectly :) Link to comment https://forums.phpfreaks.com/topic/35786-deleting-a-file/#findComment-169587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.