Forum Moderators: coopster

Message Too Old, No Replies

How to display a text document on a single php document -Script

display text document on single php document

         

chikooo

4:41 pm on Feb 22, 2009 (gmt 0)

10+ Year Member



is there a way that i can display a text document on a php document. lets say the text document is called "text.txt" and i want to display the content of it on a php file and then when use next page on the php documenht to go to the next page a keep viewing the rest of the content of the text document

chikooo

5:23 pm on Feb 22, 2009 (gmt 0)

10+ Year Member



i was thingking that when i click next it will take me to the next page using this kind of url
[mydomain.com...]

enigma1

1:53 pm on Feb 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to define some sort of pagination. For the first step to read and output the text file via php

<?php
define('PAGE_SIZE', 1000);
$filename = 'file.txt';
$handle = fopen($filename, "r");
if( !$handle ) {
echo 'file error';
exit();
}
$filesize = filesize($filename);
$start = $offset = 0;
if( isset($_GET['start']) ) {
$start = (int)$_GET['start'];
$offset = $start*PAGE_SIZE;
}
$start++;
fseek($handle, $offset);
$contents = '';
if (!feof($handle)) {
$contents .= fread($handle, PAGE_SIZE);
}
fclose($handle);
echo $contents;

echo '<br /><br /><a href="http://www.example.com/index.php?start=' . $start . '">Goto Page ' . $start . '</a>';
?>