
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 0.93 KB | hits: 10 | expires: Never
Display contents of static files across multiple pages in PHP
function printFile($file) {
$handle = fopen("$file", "r");
while (!feof($handle)) {
echo fgets($handle) . "<br>";
}
echo "<hr>";
fclose($handle);
}
$files = scandir($directory);
$number = count($files, 0);
while ($number > 2) {
$number--;
$FileToPrint = $directory . $files["$number"];
echo $FileToPrint . "<br>";
printFile("$FileToPrint");
}
// initialize some settings
$perPage = 20;
$page = intval($_GET['page']);
// getting the files (just *.txt)
$files = glob('directory/*.txt');
$numFiles = count($files);
// displaying the files for this page
$offset = $page * $perPage;
for($i = $offset; $i < ($offset + $perPage); $i++){
// just print the filename for now
echo $files[$i]. "<br>";
}
// page browser
$numPages = ceil($numFiles / $perPage);
for($i = 0; $i < $numPages; $i++){
echo '<a href="yourpage.php?page='.$i.'">'.$i.'</a>';
}