deleting few images from the folder

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cooler75
Forum Commoner
Posts: 40
Joined: Wed May 29, 2002 2:43 pm
Location: RichIsland

deleting few images from the folder

Post by cooler75 »

hello,
i thought i had a perfect upload script, but... :oops:
i searched the forum and found no answer. :x

I have one upload script that allow user to upload up to 4 images for a listing. When the user decide to delete a listing, the listing, the info and all the images will be deleted.

However, my script wont allow me to do that. When i click delete, it only delete the first image & thumb image that the user upload.
here is my delete link:

Code: Select all

echo "<a href="./mgradmin.php?delete=$a_rowїid]&file_name=$image_rowїfile_name]&thumb_file_name=$image_rowїthumb_file_name]" 
onClick="return confirmDelete()">delete listing</a>";
And here is my delete script:

Code: Select all

//DELETE A RECORD
if ($delete != "")
   {
   //delete listing here
   $query = "DELETE FROM homes WHERE ((id = '$delete') AND (owner = $current_user))";
   if (!mysql_query ($query, $link) )
   {
   die (mysql_error());
   }
   Print "<table cellspacing=5 cellpadding=5 width=100%><tr><td>";
   print "<table border=0 cellspacing=0 cellpadding=5 width=100%><tr><td height=28>";
   print "<font face="Verdana" size=2><b>Listing #$delete has been removed...<br>";
   

   //delete image infomation from the db
   $query = "DELETE FROM tbl_thumb WHERE ((prop_num = '$delete') AND (owner = '$current_user'))";
   if (!mysql_query ($query, $link) ){die (mysql_error());}

   unlink("$listings_upload_path/$file_name");
   unlink("$listings_upload_path/$thumb_file_name");
   print "Images for listing #$delete have also been removed...</b></font>";
   Print "</td></tr></table></td></tr></table><br>";
   }
Like say the user upload 3 images, so there would be 3 original images, and 3 thumb images in the directory, but when i delete the listing, only the first image and the first thumbnail is being deleted, so when i browse the directory, i still see 4 images.

Can somebody tell me what i did wrong in my script

thank you very much
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I don't get it. Where is the script supposed to delete more than one image?
There's only one filename (&file_name=$image_row[file_name]& and only one unlink for that ( unlink("$listings_upload_path/$file_name");)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I have this php book which has a nice File Manager script in it. The script is avaible online here: http://dmcinsights.com/php/downloads/10.zip

Thats all of chapter 10's downloads. Enjoy!
cooler75
Forum Commoner
Posts: 40
Joined: Wed May 29, 2002 2:43 pm
Location: RichIsland

Post by cooler75 »

thank you for replying guru,
yeah, i noticed that, no script to delete more than one image.
and i have managed to add couple lines to my original script:

Code: Select all

$query = "SELECT file_name, thumb_file_name FROM tbl_thumb WHERE ((ID = $delete) AND (owner='$current_user'))";
        $result = mysql_query ($query) or die(mysql_error().'<p>'.$query.'</p>');
        while ($image_row =mysql_fetch_array ($result) )
        {
        unlink("$listings_upload_path/$image_rowїfile_name]");
        unlink("$listings_upload_path/$image_rowїthumb_file_name]");
        }
So i am assuming whatever I did up there would allow me to select all images uploaded by the same user. Now, what do i have to do with my delete link and unlink? I did try with whatever i did, but this time with the script up there, no images was deleted, something must've been wrong.

sorry, need help with this and still a newbie :oops:
thank you
Post Reply