Home >Backend Development >PHP Problem >How to convert images into binary strings in php

How to convert images into binary strings in php

藏色散人
藏色散人Original
2020-08-25 09:26:393019browse

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.

How to convert images into binary strings in php

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=&#39;$strData&#39;>
function base64EncodeImage($strTmpName)
{
    $base64Image = &#39;&#39;;
    $imageInfo   = getimagesize($strTmpName);
    $imageData   = fread(fopen($strTmpName , &#39;r&#39;), filesize($strTmpName));
    $base64Image = &#39;data:&#39; . $imageInfo[&#39;mime&#39;] . &#39;;base64,&#39; . 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn