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条)

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样