Jump to content

Listing a Directory


monkeytooth

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/209456-listing-a-directory/
Share on other sites

<?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);
          }
      }
?>

Link to comment
https://forums.phpfreaks.com/topic/209456-listing-a-directory/#findComment-1093785
Share on other sites

Archived

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

×
×
  • 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.