https://dev.webpages.dk/  
 
PHP How to Read from a File
How to Read from a File:

We open the file with 'fopen' and read from it using 'fread'.
Using 'filesize($viewme)' will get the size of the file we open, as this is needed for the 'fread'. Using it like this it will read the size of the complete file.

To the right of here you can see the different options you have to use with the 'fopen'.

 Read from a File

How do you read from a file using PHP?

.. this could be any filetypes that are flatfiles. Like PHP, CSS, HTML, XML, TXT, Javascripts, and many many more.

fopen have following options;

'r' (read only, file pointer at the beginning)
'r+' (read and write, file pointer at the beginning)
'w' (write only, file pointer at the beginning, zero length file, create it if it does not exist)
'w+' (read and write, file pointer at the beginning, zero length file,
create it if it does not exist)
'a' (write only, file pointer at the end, zero length file)
'a+' (read and write, file pointer at the end, zero length file)
'x' (write only, file pointer at the beginning, if exists, return FALSE)
'x+' (read and write, file pointer at the beginning, if exists, return FALSE)

 HTML

<HTML><BODY> 
<TABLE> 
<FORM METHOD='POST' ACTION=''> 
<TR> 
<TD>Click here to read file: </TD> 
<TD><INPUT TYPE='submit' NAME='doit' VALUE='Read textfile'></TD> 
</TR></FORM> 
</TABLE> 
</BODY></HTML>

 PHP

<?php
if (isset($_POST['doit']))  { 
    $viewme = 'file.txt'; 
    $file = fopen($viewme, 'r'); 
    $string = fread( $file, filesize($viewme) ); 

    echo "<TEXTAREA ROWS='24' COLS='80'>"; 
    echo $string; 
    echo "</TEXTAREA>"; 
    exit(); 
} 
?>
Icons made by Freepik from www.flaticon.com On this page you are shown how you can read content from a file, and show it
08:08:26