PDA

View Full Version : Displaying contents of txt files in a directory


Errica
10-30-2005, 02:40 PM
Is there a way, using php, to pull the content of all txt files in a directory and display it along with the file name?

devinemke
10-31-2005, 04:28 PM
<?php
$path = '/path/to/textfiles/';
$handle = opendir($path);
while (($filename = readdir($handle)) !== false)
{
if ($filename != '.' && $filename != '..')
{
$pathinfo = pathinfo($path . $filename);
if (isset($pathinfo['extension']) && strtolower($pathinfo['extension']) == 'txt')
{
echo 'contents of ' . $path . $filename . ':<br>';
readfile($path . $filename);
echo '<hr>';
}
}
}
?>

Errica
10-31-2005, 04:42 PM
NICE! Thank you!

Errica