Jump to content

Archived

This topic is now archived and is closed to further replies.

craigbruiners

Need help with checking files in database

Recommended Posts

Hi there,

Can anybody please help me with getting code to do the following.

I want to run a php file that coz through the database to check the files(.jpg's) that it needs and then display only all the uneccessary files(.jpg's) which is not needed, so that i can remove them from the database.

Thanks alot.

Share this post


Link to post
Share on other sites
How is a file deemed unnecessary?

Share this post


Link to post
Share on other sites
[!--quoteo(post=385619:date=Jun 19 2006, 08:00 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Jun 19 2006, 08:00 AM) [snapback]385619[/snapback][/div][div class=\'quotemain\'][!--quotec--]
How is a file deemed unnecessary?
[/quote]

[img src=\"style_emoticons/[#EMO_DIR#]/excl.gif\" style=\"vertical-align:middle\" emoid=\":excl:\" border=\"0\" alt=\"excl.gif\" /] Well because a collegue updated the site but didnt remove the old images in the folder, so now we need to check which of the files(.jpg's) are needed and which are not needed anymore before we delete the wrong files but if i have to do it manually then i have to delete about 500-1000 files(which will take forever).

Share this post


Link to post
Share on other sites
[!--quoteo(post=385622:date=Jun 19 2006, 02:11 PM:name=craigo)--][div class=\'quotetop\']QUOTE(craigo @ Jun 19 2006, 02:11 PM) [snapback]385622[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[img src=\"style_emoticons/[#EMO_DIR#]/excl.gif\" style=\"vertical-align:middle\" emoid=\":excl:\" border=\"0\" alt=\"excl.gif\" /] Well because a collegue updated the site but didnt remove the old images in the folder, so now we need to check which of the files(.jpg's) are needed and which are not needed anymore before we delete the wrong files but if i have to do it manually then i have to delete about 500-1000 files(which will take forever).
[/quote]
I think you missunderstood me. How is PHP supposed to know if a file is not needed? Are you comparing the files in a directory to a list of files that are not needed, comparing to database enteries, or something else?

Share this post


Link to post
Share on other sites
[!--quoteo(post=385625:date=Jun 19 2006, 08:18 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Jun 19 2006, 08:18 AM) [snapback]385625[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I think you missunderstood me. How is PHP supposed to know if a file is not needed? Are you comparing the files in a directory to a list of files that are not needed, comparing to database enteries, or something else?
[/quote]

I want to compare it to database enteries.

Share this post


Link to post
Share on other sites
You could probably do this be creating two arrays, one containing all of the files referenced in the database and the other containing all of the files actually in the directory. Compare the two arrays, and delete any files from the directory that are returned by the comparisson.

Heres the functions I'd use...

glob() - To get an array of files from a directory
array_diff() - To compare the two arrays
unlink() - To delete files

Mixed with the usual MySQL functions and control structures.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.