Jump to content


Photo

Need help with checking files in database


  • Please log in to reply
5 replies to this topic

#1 craigbruiners

craigbruiners
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 19 June 2006 - 12:52 PM

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.

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 19 June 2006 - 01:00 PM

How is a file deemed unnecessary?

#3 craigbruiners

craigbruiners
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 19 June 2006 - 01:11 PM

[!--quoteo(post=385619:date=Jun 19 2006, 08:00 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Jun 19 2006, 08:00 AM) View Post[/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).

#4 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 19 June 2006 - 01:18 PM

[!--quoteo(post=385622:date=Jun 19 2006, 02:11 PM:name=craigo)--][div class=\'quotetop\']QUOTE(craigo @ Jun 19 2006, 02:11 PM) View Post[/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?

#5 craigbruiners

craigbruiners
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 19 June 2006 - 01:23 PM

[!--quoteo(post=385625:date=Jun 19 2006, 08:18 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Jun 19 2006, 08:18 AM) View Post[/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.


#6 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 19 June 2006 - 01:53 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users