PHP » I/O » fpassthru()

Syntax:
bool fpassthru(int fh)
fh
Handle of the file to dump.

Dumps a file to the browser.

This function sends the contents of a file directly to the browser. The file needs to be opened first, since fpassthru() expects a file handle. Reading starts at the current position of the file pointer, which means that it is possible to skip the beginning of a file. This function can be used on binary files. TRUE is returned on success, and FALSE on failure.

Examples

Code:
<?php

Header("content-type:image/jpeg");
$fh = fopen("picture.jpg", "r");
fpassthru($fh);
close($fh);

?>
Output:
An image is displayed.
Explanation:

This example shows how fpassthru() can be used to send binary data from a program to the browser. A page with this code can be used in an img tag (<img src="fpassthru.php">), to show the image on a different page.

See Also: