如何从PHP中的base 64字符串获取图像大小

  发布于 2023-01-04 14:01

我正在为图像的字符串获取base 64,我必须将其移动到文件夹中并将图像路径存储在数据库中,但必须限制文件大小。我该如何做:

我的从base 64字符串生成图像的代码如下:

/** if image is attached with request **/
 $Image = "MyBase64StringHere";
 list($type, $Image) = explode(';', $Image);
 list(, $Image)      = explode(',', $Image);

/** decode the base 64 image **/
 $Image = base64_decode($Image);

I have tried to get image size like:
$size =  getimagesize($Image);

但是从中获取文件的宽度和高度,有人可以告诉我如何从中获取文件的大小。

1 个回答
  • 请检查:

    解码后,请尝试使用:getimagesizefromstring(),如果您使用PHP 5.4,如果使用PHP 5.3,则可以使用以下方法进行检查。

    <?php
    if (!function_exists('getimagesizefromstring')) {
        function getimagesizefromstring($data)
        {
            $uri = 'data://application/octet-stream;base64,' . base64_encode($data);
            return getimagesize($uri);
        }
    }
    

    2023-01-04 14:04 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有