php size of base64_encode string - file

synonym picture synonym · Mar 21, 2011 · Viewed 20.1k times · Source

I'm wondering how could I know the file size of a base64_encoded string? For instance:

$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
       . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
       . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
       . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data = base64_decode($data);

Thanks

Answer

Marc B picture Marc B · Mar 21, 2011
strlen(base64_decode($encoded_data));

And as a rough rule of thumb, base64 encoding increases the original data in size by about 33%