问题描述
如何从php中的字符串获取文件大小"?
how can i get the "filesize" from a string in php?
我将字符串作为blob放在mysql数据库中,我需要存储blob的大小.我的解决方案是创建一个临时文件,并将字符串放入临时文件.现在我可以从字符串"中获取文件大小.但这解决方案不好...
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...
问候
推荐答案
这要视情况而定.如果您启用了 mbstring函数重载,则唯一有效的调用将是mb_strlen($string, '8bit');
.如果未启用,strlen($string)
也可以正常工作.
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);
}
这篇关于从字符串文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!