Jump to content

HELP: Deleting images associated in database


mista_sage

Recommended Posts

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!  ;D

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' );
   }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.