954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How can i delete unused and unneeded images from a folder using php ?

Hi all
i need to know if there is by a way by any chance to delete unused images from my virtual directory or wwwroot folder dunamically on the user request using php ?
thank you all

Decency
Newbie Poster
22 posts since Aug 2004
Reputation Points: 10
Solved Threads: 1
 

Yes this should be possible. There may be some scripts already written to do this although I am not aware of them. You could try searches on google and yahoo to see what you can find. If you don't find anything useful, you will find most of the php functions you will need here .

DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 

thank you for such a wonderful reference you gave me
i checked it out and found the way to delete files and folders
and it was just so simple lol

for your reference the code is as this :

<?php

unlink("filename");

?>

can it be more simple ?
lol

Decency
Newbie Poster
22 posts since Aug 2004
Reputation Points: 10
Solved Threads: 1
 
thank you for such a wonderful reference you gave me i checked it out and found the way to delete files and folders and it was just so simple lol for your reference the code is as this : <?php unlink("filename"); ?> can it be more simple ? lol



is that the same for deleting folders too?

Killer_Typo
Master Poster
781 posts since Apr 2004
Reputation Points: 152
Solved Threads: 39
 

To remove a directory:

rmdir('directory_name');

DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 

yeah its the same but sometimes the delete() function does not work on certain systems so you will need to use unlink() or unset()

Decency
Newbie Poster
22 posts since Aug 2004
Reputation Points: 10
Solved Threads: 1
 

I think you need the right file system permissions.

Gary King
PHP/vBulletin Guru
Team Colleague
417 posts since Nov 2003
Reputation Points: 53
Solved Threads: 5
 

it would be better to check 1st if the file is in the directory ^^
i got this from the php manual :)
hope it helps you as well
<?php
if(file_exists($file))
unlink($file);
?>

charvie
Newbie Poster
24 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You