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

Nikola Nastevski picture Nikola Nastevski · Mar 2, 2012 · Viewed 128.8k times · Source

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.

Answer

Frxstrem picture Frxstrem · Mar 2, 2012

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.