mista_sage Posted August 11, 2007 Share Posted August 11, 2007 Hi, I've got a database structure with rows containing filenames of photos on the server each with its own uploader/user and unique id number. Can someone help me on how to delete an array of photos from the server uploaded by a specified uploader/user? any help greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/64370-help-deleting-images-associated-in-database/ Share on other sites More sharing options...
Guest Posted August 11, 2007 Share Posted August 11, 2007 It probably will look something like this (do NOT use this as-is. It has NO error handling) <?php $dbh = mysql_connect('localhost', 'admin', '123'); mysql_select_db('myDB', $dbh); $rs = mysql_query('SELECT user, filename FROM photos', $dbh); while( $results = mysql_fetch_assoc($rs, $dbh) ) { unlink( 'uploader/' . $results['user'] . '/' . $results['filename'] ); } ?> OR if you don't have a filename column (and need to use an ID column) <?php $dbh = mysql_connect('localhost', 'admin', '123'); mysql_select_db('myDB', $dbh); $rs = mysql_query('SELECT user, id FROM photos', $dbh); while( $results = mysql_fetch_assoc($rs, $dbh) ) { unlink( 'uploader/' . $results['user'] . '/' . $results['id'] . '.jpg' ); } ?> Link to comment https://forums.phpfreaks.com/topic/64370-help-deleting-images-associated-in-database/#findComment-320980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.