example:
/New folder
new.txt
left.gif
download.zip
dc.exe
....so is there..?
| |
|
Welcome to KnowledgeSutra - Dear Guest | |
Posted 06 March 2005 - 02:14 PM
<?php $folder_content = 'echo "The following files are content of the selected folder:" echo "$list"'; $list= "new.txt, left.gif, download.zip, dc.exe"; echo "$folder_content"; ?>
Posted 06 March 2005 - 03:13 PM
Corey, on Mar 6 2005, 09:42 AM, said:
<?php
if ($handle = opendir("yourdirhere")) {
while (($file = readdir($handle)) !== false) {
echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
}
closedir($dh);
}
?>
Note that this will also list sub-directories and '.' and '..'. You can get info in the php.net documentation for opendir().
Posted 07 March 2005 - 11:39 AM
$directory = "path/to/dir";
while (($item = $directory->read()) !== false) {
if ($item != "." && $item != "..") {
$path = "{$directory->path}/{$item}";
if (is_dir($path)) {
$tmp['name'] = $item;
$tmp['stats'] = lstat($path);
$dirs[$item] = $tmp;
unset($tmp);
} elseif (is_file($path)) {
$tmp['name'] = $item;
$tmp['stats'] = lstat($path);
$tmp['extension'] = substr($item, strrpos($item, "."));
$files[] = $tmp;
unset($tmp);
}
}
}
ksort($dirs, SORT_STRING);
sort($dirs);
ksort($files, SORT_STRING);
sort($files);
Posted 23 March 2011 - 01:04 AM
function get_dirlist( $path, $match = '*', $exclude = array( '.', '..' ) )
{
$result = array();
if( ( $handle = opendir( $path ) ) )
{
while( false !== ( $fname = readdir( $handle ) ) )
{
$skip = false;
if( !empty( $exclude ) )
{
if( !is_array( $exclude ) )
$skip = fnmatch( $exclude, $fname );
else
{
foreach( $exclude as $ex )
{
if( fnmatch( $ex, $fname ) )
$skip = true;
}
}
}
if( !$skip && ( empty( $match ) || fnmatch( $match, $fname ) ) )
$result[] = $fname;
}
closedir( $handle );
}
return $result;
}
$list = get_dirlist( '.' ); foreach( $list as $fname ) echo "<p><a href=\"$fname\">$fname</a></p>\n";
$exclude = array ( '.', '..', 'index.php' ); $list = get_dirlist( '.', '*.php', $exclude ); foreach( $list as $fname ) echo "<p><a href=\"$fname\">$fname</a></p>\n";
Posted 07 October 2011 - 12:45 AM
Corey, on 06 March 2005 - 08:42 AM, said:
<?php
function getFileList($dir)
{
// 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") && is_readable("$dir$entry")) {
$retval[] = "$dir$entry";
}
}
$d->close();
return $retval;
}
// for example your folder name is img for the time being..
$dirlist = getFileList("img");
echo "<pre>",print_r($dirlist),"</pre>";
?>
and execute it... And it will give you an array containing the list of all files of that folder, it simple skips the folders and hidden files.
0 members, 1 guests, 0 anonymous users