Hi can anyone tell me the best way to read/list the files in a directory and then add those filenames to a database?

Thanks all

Biscutty

    Hi,
    you can read file by file from dir and put each one in the db:

    if ($dir = opendir($name)) 
      while (($namefile = readdir($dir)) !== false)
                //do any insert
    

    For more info check manual for opendir() function.
    http://www.php.net/manual/en/ref.dir.php

    see you

      Try a search on the "directory listing"-subject. There are a lot of post on this on this forum, and I successfully made a function for this myself about a couple of months ago after a quick search on "directory AND list" or something like that...

      I suggest a simple conditional statement to insert the filename/fileinfo to the database.

        Thanks, but is it best to list the file names into an array and then insert the array into the database, or loop through each file, inserting it one at a time?

        thanks

          hmmm...
          I experienced out that the only problem is the multi-execution, if two guys load this page... Else using array is more clean, but slower...

            Write a Reply...