0

hello,


is it possible to delete waste images from folder using php.
for suppose user uploaded images....after his account expires his account will be deletes by admin. at the same how to delete his photos from folder.

Edited by muralikalpana: n/a

5
Contributors
7
Replies
8
Views
8 Years
Discussion Span
Last Post by leviathan185
1

yeah its pretty much possible... retrieve the name of image file being used by that account.
after that its just a simple unlink call... Do this in admin's account deletion script
if u need more help... just post up ur deletion code here

hello,


is it possible to delete waste images from folder using php.
for suppose user uploaded images....after his account expires his account will be deletes by admin. at the same how to delete his photos from folder.

Edited by venkat0904: n/a

0

yeah its pretty much possible... retrieve the name of image file being used by that account.
after that its just a simple unlink call... Do this in admin's account deletion script

i was already deleted images which is in database.i am not talking about admin side. i am talking about images which is in folder when we are uploadimages that images are stores in one folder. i want to delete images from that folder.

0

Thats exactly what i am talking about... before deleting the image entry from ur database, get the file name and call unlink() function...
u can happily delete it from ur database after that..
hope i made my point clear

i was already deleted images which is in database.i am not talking about admin side. i am talking about images which is in folder when we are uploadimages that images are stores in one folder. i want to delete images from that folder.

0

Thats exactly what i am talking about... before deleting the image entry from ur database, get the file name and call unlink() function...
u can happily delete it from ur database after that..
hope i made my point clear

$qDelUsers = "UPDATE duckdecoy_product  SET product_image = '' WHERE `product_id` ='$id'";
	getSqlQuery($qDelUsers);

above code is for assigning null value to product image when i am deleting product. after that what will i do to delete from folder?

0

After executing the above query.Get the image name with path.Then use the unlink function .

$img = "Full img path with file name";
eg:$img = "admin/uploads/images/test.jpg";

unlink ($img);
0
//e.g. in a config file - although should this be a constant as opposed to a variable?
 
$base_image_directory = $_SERVER['DOCUMENT_ROOT'] . "/admin/uploads/images/";

//In any file within the site - no relative references to worry about.
  unlink($base_image_directory . 'test.jpg');

Mind you a delete_img($file) function may be a better way.

0

it would also be a good idea to place the delete from database call inside an if statement, that way if the file delete fails you will still have the database info. That kind of coincides with ardavs comment.

<?php
   if(unlink($file)) {
      // delete info from database
   }
<?
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.