|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I need to be able to do the following procedure; 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. This will run via cron Has anyone done something similar before, willing to assist me with a basicscope of actions to work on? Thanks in advance Steven |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Steven Macintyre wrote:
> Hi, > > I need to be able to do the following procedure; > > 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. > > This will run via cron > > Has anyone done something similar before, willing to assist me with a basic scope of actions to work on? Hi, Do you already have some code? Do you got stuck somewhere? Aschwin Wesselius |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
I handle your object a different and, I believe, a simpler way.
Instead of a cronjob, I call a cleanup function whenever a page is opened. Obviously, this approach requires a time overhead and thus is not good for very high volume sites. You can mitigate this drawback by maintaining a simple touch() file that keeps track of the time when your cleanup function is run and insure it only runs once a day, or whatever frequency you need. You can even make the file sticky so it stays in memory to further reduce the overhead. Steven Macintyre wrote: > Hi, > > I need to be able to do the following procedure; > > 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. > > This will run via cron > > Has anyone done something similar before, willing to assist me with a basic scope of actions to work on? > > Thanks in advance > > Steven > |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
At 9:35 AM +0100 3/13/08, Steven Macintyre wrote:
> Hi, > >I need to be able to do the following procedure; > >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. > >This will run via cron > >Has anyone done something similar before, willing to assist me with >a basic scope of actions to work on? > >Thanks in advance > >Steven Steven: Are you saying that if images exist in your database AND appear in the file system, then don't delete them? Why not give your approved images a prefix and just delete everything that doesn't via a cron? Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Steven Macintyre wrote:
> Hi, > > I need to be able to do the following procedure; > > 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. > > This will run via cron > > Has anyone done something similar before, willing to assist me with a basic scope of actions to work on? > > Thanks in advance > > Steven > Maybe a dumb question, but after truing up the db and fs, why not delete the file when you delete from the db? -Shawn |
|
![]() |
| Outils de la discussion | |
|
|