php method to convert images into binary strings: first obtain the temporary file name through the "$_FILES['file']['tmp_name'];" method; then convert the image file into binary through the base64EncodeImage function Stream; finally output the conversion result.
Recommended: "PHP Video Tutorial"
php converts images into binary streams
//Get the temporary file name
$strTmpName = $_FILES['file']['tmp_name'];
//Convert to binary stream
$strData = base64EncodeImage(strTmpName );
//Output
<img src='$strData'>
function base64EncodeImage($strTmpName) { $base64Image = ''; $imageInfo = getimagesize($strTmpName); $imageData = fread(fopen($strTmpName , 'r'), filesize($strTmpName)); $base64Image = 'data:' . $imageInfo['mime'] . ';base64,' . chunk_split(base64_encode($imageData)); return $base64Image; }
The above is the detailed content of How to convert images into binary strings in php. For more information, please follow other related articles on the PHP Chinese website!