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.
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.
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.
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.
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.
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?
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);
//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.
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
}
<?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.