How to convert php images into binary streams

藏色散人
Release: 2023-03-08 12:02:01
Original
2660 people have browsed it

How to convert php images into binary streams: first create a PHP sample file; then get the temporary file name; finally use the "base64EncodeImage(strTmpName);" method to convert the image files into binary streams.

How to convert php images into binary streams

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer.

php converts images into binary streams

//获取临时文件名 $strTmpName = $_FILES['file']['tmp_name'];
Copy after login
//转成二进制流 $strData = base64EncodeImage(strTmpName );
Copy after login
//输出 
Copy after login
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; }
Copy after login

[Recommended:PHP video tutorial]

The above is the detailed content of How to convert php images into binary streams. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!