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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -