Re: getting download resume to work
| From: | Chris Shiflett | Date: | Fri, 12 Sep 2003 03:21:27 +0000 |
| Subject: | Re: getting download resume to work | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-162378@lists.php.net to get a copy of this message | ||
Can you help explain this code? It looks like you're on the right track but
have a few flaws (at first glance).
> <?php
> session_cache_limiter('public');
> session_start();
Is there a reason to be using sessions here?
> set_time_limit(0);
> $file=$_REQUEST['file'];
> $extstart=strpos($file, ".");
What does $extstart contain now?
> $ext=substr($file, $extstart+1);
So $ext is now a piece of the file. Why?
> $dir="d:\\downloadable_courses";
> $size=filesize($dir."\\".$file);
> header("Accept-Ranges: bytes");
So $size is now the size of the entire file (not the piece).
> if(isset($_ENV['HTTP_RANGE'])) {
> list($a, $range)=explode("=",$_ENV['HTTP_RANGE']);
So $a is now bytes, and $range is something like 123-456
> str_replace($range, "-", $range);
This makes no sense. The range requested is bytes 123 through 456, and you're
converting this to 123456. Why?
> $size2=$size-1;
> header("Content-Range: $range$size2/$size");
> $new_length=$size2-$range;
This will definitely not work, based on my comments above.
If someone sends this header:
Range: bytes=0-1023
and your resource is 2048 bytes in size, your response should include this
header:
Content-Range: bytes 0-1023/2048
Work on generating the correct string before you bother actually using them as
headers and trying for the full solution.
Hope that helps.
Chris
=====
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/