How PHP converts images into binary output: This can be achieved through the fopen() function in combination with the fread() function. The fopen() function can open a file or URL. The fread() function is used to read an open file and returns the read string.
Related function introduction:
(Recommended tutorial: php tutorial)
1. fopen function
fopen() function opens a file or URL.
If fopen() fails, it will return FALSE with an error message. You can hide error output by adding an '@' in front of the function name.
Syntax
fopen(filename,mode,include_path,context)
Parameter introduction:
2. fread function
fread() function reads the open file. The function will stop running when it reaches the specified length or reaches the end of file (EOF) (whichever comes first). This function returns the string read, or FALSE on failure. Syntaxstring fread ( resource $handle , int $length )
header( "Content-type: image/jpeg"); $PSize = filesize('1.jpg'); $picturedata = fread(fopen('1.jpg', "r"), $PSize); echo $picturedata;
The above is the detailed content of How to convert images into binary output in php. For more information, please follow other related articles on the PHP Chinese website!