Jump to content

Need help with checking files in database


craigbruiners

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.
Link to comment
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).
Link to comment
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?
Link to comment
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.
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.