$location = '文件绝对路径';
$this->read_file = $location;
$read_file_handle = fopen($location, 'r');
return $this->set_read_stream($read_file_handle,$location);//调用
public function set_read_stream($resource, $file = null,$size = null)
{
if (!isset($size) || $size < 0)
{
$stats = fstat($resource);
if ($stats && $stats['size'] >= 0)
{
$position = ftell($resource);
if ($position !== false && $position >= 0)
{
$size = $stats['size'] - $position;
}
}else{
//第三方获取大文件的文件大小
if (!(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN'))
$size = trim('stat -c%s $file');
else {
// 必须开启修改 com.allow_dcom = true,开启extension=php_com_dotnet.dll 扩展
$com=new COM('Scripting.FileSystemObject');
$file=$com ->getfile($file); //FSO要使用绝对路径的
$size = $file->Size;
}
}
}
$this->read_stream = $resource;
return $this->set_read_stream_size($size);
}
注:$file 为文件绝对路径
php 获取超2G文件的文件size(含压缩包)
于 2022-02-28 09:29:34 首次发布