【发布时间】:2020-08-12 20:48:50
【问题描述】:
我正在获取图像字符串的 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);
但是从中获取文件的宽度和高度。有人可以告诉我如何从中获取文件大小。谢谢
【问题讨论】:
-
您的
$path包含相对路径,请您尝试使用绝对路径 - 比如http://www.example.com/uploads/....jpg。 -
strlen($Image)可以吗? -
@Lashane,
strlen用于获取字符串长度。 OP 需要图片尺寸。 -
@prava OP 想要文件大小,在这种情况下等于字符串长度
-
但是我想在移动到文件夹之前验证图像大小,可以吗?
标签: php file-upload base64