首页 文章

我的chunksize中没有足够的块 - PHP下载脚本导致20%的文件大小下载

提问于
浏览
1

试图下载整个文件 - 但我假设脚本正在退出流中的第一个chunksize传递 .

需要编写什么才能获得完整的文件大小下载?

$image_link=$_GET['image_link'];
$fullPathDL=$path0.$image_link;
$fsize = filesize($fullPathDL);
$path_parts = pathinfo($fullPathDL);
if ($fd = fopen($fullPathDL, "rb")) {
    $fsize = filesize($fullPathDL);
    header("Content-type: application/jpg"); // add here more headers for diff. extensions
    header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
    header("Content-length: $fsize");
    //    header("Cache-control: private"); //use this to open files directly
        while(!feof($fd)) { 

        $buffer = fread($fd, 8192); 

        echo $buffer;
    }

fclose ($fd);
exit;

}

1 回答

  • 1

    您的示例不起作用的原因是缓冲区中完全存在 . 我看了标准已经有一段时间了,但至少我能给你一个正确的方向 . 基本上,当从chunked-transfer读取时,我认为前几个字节代表块中的字节数 . 像这样的东西(取自维基百科) .

    25
    This is the data in the first chunk
    
    1C
    and this is the second one
    
    3
    con
    8
    sequence
    0
    

    您基本上需要检查要读取的字节数,读取字节数,然后重复,直到要读取的字节数为0 .

    完成此操作的最简单方法是在请求标头中指定HTTP 1.0(不支持分块传输),或使用为您处理此问题的库,即CURL .

相关问题