Jump to content

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

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.