Hey,

Is there a way to get a list of files in a certain folder and run a loop to process each file? I'd like to create a page which displays each thumbnail image in a folder. I'd also like to add the location of the image to a database, if it's not there already, in order to link each thumbnail to the full image.

Is this possible? What command(s) could I use?

~JOSH

    
    $path = '/path/to/my/stuff' ;
    
    // PHP 5
    // Loop through the files in a folder
    foreach( new DirectoryIterator( $path ) as $file )
    {
      // Skip the '.' and '..' folders and subfolders
      if( $file.isDot() || $file.isDir() ) continue ;
    
      echo $file->getFileName() ; // show the file name
      echo $file->getPathName() ; // show the path
    
      // Do your database insertion here
    
    }
    
    // If you really want to get dirty you can loop through all subdirectories too
    foreach( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path )) as $file )
    {
      // Skip the '.' and '..' folders (RecursiveIteratorIteratore by default skips other folders)
      if( $file.isDot() ) continue ;
    
      echo $file->getFileName() ; // show the file name
      echo $file->getPathName() ; // show the path
    
      // Do your database insertion here
    
    }
    
      5 days later

      :glare: Realized I need to upgrade to PHP5.......

      I'll get back to ya once that happens and I test the script.

      Thanks for such a quick response.

      ~JOSH

        Write a Reply...