Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

filesize from a String

how can i get the "filesize" from a string in php?

I put the string in a mysql database as a blob and i need to store the size of the blob. My solution was to create a temp file and put the string into the temp file. now i can get the filesize from the "string". but that solution is not good...

greetings

like image 931
poldixd Avatar asked Aug 18 '10 10:08

poldixd


1 Answers

It depends. If you have mbstring function overloading enabled, the only call that will work will be mb_strlen($string, '8bit');. If it's not enabled, strlen($string) will work fine as well.

So, you can handle both cases like this:

if (function_exists('mb_strlen')) {
    $size = mb_strlen($string, '8bit');
} else {
    $size = strlen($string);
}
like image 159
ircmaxell Avatar answered Oct 27 '22 23:10

ircmaxell