Jump to content

[SOLVED] grab names of all files in folder


ohdang888

Recommended Posts

how do i put all the names of the files in a folder into an array without manually entering the name of each file????

 

thanks.

 

 

 

(i have over 100 graphics i need documented, and really don't want to have to do this by manually entering the names in by hand. blah)

 

 

Here is one that will do a recursive dir list. It does not return directories.

 

<?php
set_time_limit(180);

  function getFileList($dir, $recurse)
  {
    $deleted=0; 
# array to hold return value
    $retval = array();

    # add trailing slash if missing
    if(substr($dir, -1) != "/") $dir .= "/";

    # open pointer to directory and read list of files
    $d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
    while(false !== ($entry = $d->read())) 
{
      # skip hidden files
      if($entry[0] == ".") continue;
     if(is_dir("$dir$entry"))
  {
        $retval[] = array(
          "name" => "$dir$entry/",
          "type" => @mime_content_type("$dir$entry"),
          "size" => 0,
          "lastmod" => date('m/d/y h:ia ',filemtime("$dir$entry"))
        );

		if($recurse && is_readable("$dir$entry/")) 
		{
		  $retval = array_merge($retval, getFileList("$dir$entry/", true));
		}

     } 
  elseif(is_readable("$dir$entry"))
  {	
		$retval[] = array
		(
         		"name" => "$dir$entry",
         		"type" => @mime_content_type("$dir$entry"), 
          		"size" => round((filesize("$dir$entry")/ 1048576), 2).'MB',
          		"lastmod" => date('m/d/y h:ia ',filemtime("$dir$entry"))
        	);


      }
    }
    $d->close();

    return $retval;
  }

?>

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.