gpt4 book ai didi

php - 如何获取php资源的大小

转载 作者:搜寻专家 更新时间:2023-10-31 22:02:30 25 4
gpt4 key购买 nike

我有一个通用的 php 函数,它接受资源并将其下载为 csv 文件,资源是文件或 php://memory。我如何找到这个资源的大小,以便我可以设置标题内容长度

  /** 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) 从文件名中获取文件大小,但是在这个函数中我不知道/没有文件名,只是一个资源

最佳答案

fstat()可以胜任这项工作:

$stat = fstat($fil);
header('Content-Length: '.$stat['size']);

关于php - 如何获取php资源的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25888594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com