This code snippet is useful to me when I need to read all files inside a directory and showing it on web browser in PHP:
<?php
header('Content-type: text/plain; charset=utf-8');
$dir = "1"; //this is a folder containing files we want to read.
$files = scandir("$dir");
foreach($files as $key=>$value){
if(!in_array($value, array(".", ".."))){
echo "Found this file: " . $value . "<br>Begin reading...";
$currentfile = fopen($dir . "/" . $value, "r") or die("Unable to read the file!");
echo fread($currentfile, filesize($dir . "/" . $value));
echo "Reading finished.";
}
}