php将图片转成二进制流

//获取临时文件名

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

//转成二进制流

$strData = base64EncodeImage(strTmpName );

//输出


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;
}

你可能感兴趣的:(php,php)