duan00529 2012-12-27 15:32 采纳率: 100%
浏览 141
已采纳

动态选择文件的PHP文件大小

I have a php script that needs to determine the size of a file on the file system after being manipulated by a separate php script.

For example, there exists a zip file that has a fixed size but gets an additional file of unknown size inserted into it based on the user that tries to access it. So the page that's serving the file is something like getfile.php?userid=1234.

So far, I know this:

filesize('getfile.php'); //returns the actual file size of the php file, not the result of script execution

readfile('getfile.php'); //same as filesize()

filesize('getfile.php?userid=1234'); //returns false, as it can't find the file matching the name with GET vars attached

readfile('getfile.php?userid=1234'); //same as filesize()

Is there a way to read the result size of the php script instead of just the php file itself?

  • 写回答

5条回答 默认 最新

  • drazvzi741287 2012-12-27 16:50
    关注

    Someone had posted an option for using curl to do this but removed their answer after a downvote. Too bad, because it's the one way I've gotten this to work. So here's their answer that worked for me:

    $ch = curl_init('http://localhost/getfile.php?userid=1234');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //This was not part of the poster's answer, but I needed to add it to prevent the file being read from outputting with the requesting script
    curl_exec($ch);
    
    $size = 0;
    
    if(!curl_errno($ch))
    {
        $info = curl_getinfo($ch);
        $size = $info['size_download'];
    }
    
    curl_close($ch);
    
    echo $size;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料