Alex Rivera | Logout

How can I echo the whole content of a .html file in PHP?

Asked 2012-03-02T20:23:27.293
73

Is there a way I can echo the whole content of a .html file in PHP?

For example, I have some sample.html file, and I want to echo that filename, so its content should be displayed.

Edit
Report

1 Answer

122

You should use readfile():

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

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

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

except that file_get_contents() may cause the script to crash for large files, while readfile() won't.

answered 2012-03-02T20:36:40.063

Your Answer