Re: php cron to check and remove files
| From: | Per Jessen | Date: | Thu, 13 Mar 2008 12:04:34 +0000 |
| Subject: | Re: php cron to check and remove files | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-271482@lists.php.net to get a copy of this message | ||
Steven Macintyre wrote:
> retrieve all items from a mysql db table, then check to see if the
> files from that table exist on the server (images), if not, to "clean
> up" and remove the physical file - so that only the files from the db
> exist.
When you are comparing the contents of disk vs. db, you have three
possible outcomes:
1) file is listed in db, but not found on disk
2) file is found on disk, but not in db.
3) file is found on disk and in db.
I think I'd probably read the directories of where the physical files
are located into an array = files_in_disk(), then read in the file list
from the database into files_in_db(). Use array_diff() to identify the
discrepancies, then sort them out (delete file, add row, delete row).
for files_on_disk(), lookup opendir() and readdir().
for files_in_db(), lookup mysql_query() and mysql_fetch_assoc().
Will consume a lot of memory if you've got a lot of files.
/Per Jessen, Zürich