image uploading - php get file size from data uri -
i have form upload plugin in form upload image using data uri
such
$img = 'data:image/jpeg;base64,/9j/4qayrxhpz...............
i need have file size constraint such file size should not exceed 1mb.
i can image dimension(width & height) using list($width, $height) = getimagesize($img);
.
how can file size same. there pre defined function in php
can use file size of data uri
you can use strlen
size of string (and therefore, file) in bytes. base64 data ~1/3 larger binary data, don't forget base64_decode
first.
then code is:
$img = 'base64,/9j/4qayrxhpz...............'; echo 'file size: ' . strlen(base64_decode($img));
don't forget rid of headers ("data:image/jpeg", etc.) if want more accurate.
Comments
Post a Comment