2016-03-04 67 views
0

因此,这是我迄今为止在PHP端如何使用PHP和HTML显示文件的内容

<?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); 
} 
?> 

我怎么会在我的网页显示的内容已经从文件中读取?

+0

您应该'回声$ yourfile;' – aldrin27

回答

0

你可以做echo $yourfile更简单的方法!

您还应该使用readfile()

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

这将读取该文件,并将其发送到浏览器中的一个command.This是一样的。

echo file_get_contents("/path/to/file"); 
0

使用的file_get_contents()

$file = file_get_contents('names.txt', true); 
echo $file;