PHP » I/O » passthru()

Syntax:
void passthru(string command, int return_value)
command
Command to be executed.
return_value
Integer for the return value of the command.

Executes a command.

passthru() executes a command and sends the output directly back to the browser as binary data. This function should be used when the server generates binary data to be displayed in the browser, for example an image. The optional return_value holds the return value of the command.

Examples

Code:
<?php

Header("content-type:image/jpeg");
passthru("cat picture.jpg");

?>
Output:
An image is displayed.
Explanation:

This example shows how passthru() can be used to send binary data from a program to the browser. In this case, the UNIX program cat is used on an jpeg picture to send an image to the browser. A page with this code can be used in an img tag (<img src="passthru.php">), to show the image on a different page. To just show a picture like this, fpassthru() would be a more efficient alternative. However, cat could, for example, be replaced with another program that dynamically generates the picture.

See Also: