开发者

Not enough chunks in my chunksize - PHP download script result in 20% file size download

Trying to get the entire file downloaded -- but I assume the script is exiting with the first chunksize pass in the stream.

What needs to be coded in to get full file size download?

$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开发者_如何学JAVA["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;

}


The reason why your example doesn't work is the entirely present in the buffer. It's been awhile since I've looked at the standard, but at least I can give you a step in the right direction. Basically, when reading from chunked-transfer, the first couple bytes I believe represent the number of bytes in the chunk. Something like this (taken from wikipedia).

25
This is the data in the first chunk

1C
and this is the second one

3
con
8
sequence
0

You basically need to check the number of bytes to read, read the bytes, and repeat until the number of bytes to read is 0.

The easiest way to accomplish this is to either specify in your request headers HTTP 1.0 (which does not support chunked transfer), or use a library which handles this for you, i.e., CURL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜