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
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:
use mb_strlen() as then you can tell it what type of encoding the string uses (if any) to get the size of it in bytes.
before putting it into mysql, or in SQL:
Notice that lenght can be various depending on character set. If you want to have real length in bytes use strlen(), if you want to have character count use mb_strlen() (if you have utf-8 encoding for example)
SELECT length(field) FROM table
From the MySQL docs:
If all you are storing is the string, then the size should be the length of your string times the number of bytes in the charset. So for Unicode that would be 2*strlen($string).