PHP: List out items in a directory
See the contents within a directory and print them out.
Copy this code and paste it in your HTML
$dir = ".";
if( $dir_handle = opendir( $dir ) ){ while( $filename = readdir( $dir_handle ) ){ echo "filename: {$filename}<br />" ;
}
//rewinddir($dir_handle) to start over
}
}
$dir_array = scandir( $dir );
foreach( $dir_array as $file ){
if( stripos( $file, '.' ) > 0){
echo "filename: {$file}<br />";
}
}
}
Report this snippet