0

So this is what I have so far on the PHP side

<?php
if (isset($_POST['submit']))
{
    $name = $_POST['name'];
    $file = fopen("names.txt", "a+");
    fwrite($file,$name);
    fclose($file);

    $readFile = fopen("names.txt", "r");
    fread($file);
}
?>

How would I display on my webpage what has been read from the file?

Hobbs2000
  • 311
  • 1
  • 6
  • 19

2 Answers2

0

You can do echo $yourfile simpler way!

You should also use readfile():

readfile("/path/to/file");

This will read the file and send it to the browser in one command.This is same as.

echo file_get_contents("/path/to/file");
Shashank Shah
  • 2,077
  • 4
  • 22
  • 46
0

Use file_get_contents()

$file = file_get_contents('names.txt', true);
echo $file;
Gopalakrishnan
  • 957
  • 8
  • 19