craigbruiners Posted June 19, 2006 Share Posted June 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12370-need-help-with-checking-files-in-database/ Share on other sites More sharing options...
zq29 Posted June 19, 2006 Share Posted June 19, 2006 How is a file deemed unnecessary? Quote Link to comment https://forums.phpfreaks.com/topic/12370-need-help-with-checking-files-in-database/#findComment-47289 Share on other sites More sharing options...
craigbruiners Posted June 19, 2006 Author Share Posted June 19, 2006 [!--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). Quote Link to comment https://forums.phpfreaks.com/topic/12370-need-help-with-checking-files-in-database/#findComment-47292 Share on other sites More sharing options...
zq29 Posted June 19, 2006 Share Posted June 19, 2006 [!--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? Quote Link to comment https://forums.phpfreaks.com/topic/12370-need-help-with-checking-files-in-database/#findComment-47295 Share on other sites More sharing options...
craigbruiners Posted June 19, 2006 Author Share Posted June 19, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/12370-need-help-with-checking-files-in-database/#findComment-47298 Share on other sites More sharing options...
zq29 Posted June 19, 2006 Share Posted June 19, 2006 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 directoryarray_diff() - To compare the two arraysunlink() - To delete filesMixed with the usual MySQL functions and control structures. Quote Link to comment https://forums.phpfreaks.com/topic/12370-need-help-with-checking-files-in-database/#findComment-47307 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.