如何获得php资源的大小
我有一个常见的php函数,它接受一个资源并将其作为csv文件下载,该资源可以是一个文件,也可以是一个文件php://memory. 如何找到此资源的大小,以便设置标题内容长度如何获得php资源的大小,php,download,Php,Download,我有一个常见的php函数,它接受一个资源并将其作为csv文件下载,该资源可以是一个文件,也可以是一个文件php://memory. 如何找到此资源的大小,以便设置标题内容长度 /** Download a file as csv and exit */ function downloadCsv($filName, $fil) { header("Content-Type: application/csv"); header("Content-Disposition: at
/** Download a file as csv and exit */
function downloadCsv($filName, $fil) {
header("Content-Type: application/csv");
header("Content-Disposition: attachement; filename=$filName");
// header("Content-Length: ".......
fpassthru($fil);
exit;
}
我可以看到如何使用filesize($filename)从文件名中获取文件大小,但是在这个函数中,我不知道/没有文件名,只是一个资源php://temp/ 或php://memory/ 我可以做这项工作:
$stat = fstat($fil);
header('Content-Length: '.$stat['size']);
$stat = fstat($fil);
header('Content-Length: '.$stat['size']);