This function will grab the contents of a file but instead of putting them into a variable, the contents are displayed.

Similar to other file functions, set the second parameter to true if you want to search for your file in the include path. The third parameter is for your stream context (see manual).

Be sure to send any necessary headers prior to calling this function. For example, an image or pdf would need the proper Content-Type header.

This function returns false on an error. Otherwise, the number of bytes read from the file is returned.

$bytes = readfile( 'output.txt' );
// the contents of output.txt would have been displayed
// and $bytes would contain the number of bytes read
 
// For an image, send the proper header first
header( 'Content-Type: image/png' );
readfile( 'mypic.png' );
 
// Yes, it works with a url but you may not like the results
readfile( 'http://phpnightly.com' );