Re: Create array from directory

From: Date: Fri, 11 Apr 2003 13:00:26 +0000
Subject: Re: Create array from directory
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-143490@lists.php.net to get a copy of this message
> From: Lowell Allen <la@lowellallen.com> > >> From: Chris Blake <cblake@pbpc.co.za> >> [snip] > > $current_dir = $DOCUMENT_ROOT . "/" . $dir_name . "/"; > $dir = @opendir($current_dir); > $gallery = array(); > while ($file = readdir($dir)) { > $filepath = $current_dir . $file; > if ($file != '.' && $file != '..' && is_dir($filepath)) { > array_push($gallery, $file); > } > } > closedir($dir); > sort($gallery); The code above is a quick cut-and-paste from a script that first makes an array of subdirectories, then later makes arrays of file content -- my cut-and-paste was too quick because I grabbed the section that gets subdirectories. Replace "is_dir($filepath)" with "is_file($filepath)". -- Lowell Allen

« previous php.general (#143490) next »