php将图片转成二进制流

//获取临时文件名

$strTmpName = $_FILES['file']['tmp_name'];

//转成二进制流

$strData = base64EncodeImage(strTmpName );

//输出

<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;
}
展开阅读全文

没有更多推荐了,返回首页