monkeytooth Posted July 31, 2010 Share Posted July 31, 2010 Ok so I don't even know where to start with this idea so I thought I would poke around here for some inspiration. On my server I have a Directory. In that directory I have roughly 300 folders with 5,000 files + 1 index.php (so 5,001 files but I want to ignore the index.php in the listings) per directory. Anyway what I am trying to do is list all the files and load them into a database. What my ideal goal would be is device a script that I would put in the root directory with the 300 or so subdirectories and let it run through the directories automatically one by one, listing all the files in them and then storing them in the database. I'd break it down more but that part I can figure out on my own cause I do want to do more than just store the file names and corresponding directory its in in the DB. My issue is I can find anything or figure anything out that will cycle through all directories, thats what I need to figure out first. Quote Link to comment https://forums.phpfreaks.com/topic/209456-listing-a-directory/ Share on other sites More sharing options...
Serenitee Posted August 1, 2010 Share Posted August 1, 2010 scandir perhaps? http://www.php.net/manual/en/function.scandir.php Quote Link to comment https://forums.phpfreaks.com/topic/209456-listing-a-directory/#findComment-1093781 Share on other sites More sharing options...
harristweed Posted August 1, 2010 Share Posted August 1, 2010 <?php $directory="..\yourdirectory"; $dir="$directory"; $dp=opendir($dir); while($file = readdir($dp)){ if($file != '.' && $file != '..' ){ $insert=" insert into table ( file_name_table ) values ( '$file')"; mysql_query($insert,$link_id); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/209456-listing-a-directory/#findComment-1093785 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.