This is a discussion on Re: [PHP] getting download resume to work within the PHP General forums, part of the PHP Programming Forums category; Can you help explain this code? It looks like you're on the right track but have a few flaws (...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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/ |
|
|||
|
All answers are below your questions...
Thank you for taking the time to parse through my code and try to understand what I am doing, I really appreciate it, this is the first time I have tried something like this and have been hung up on it for a couple days now... Scott -----Original Message----- From: Chris Shiflett [mailto:shiflett@php.net] Sent: Thursday, September 11, 2003 8:21 PM To: Raditha Dissanayake; Scott Dotson; php-general@lists.php.net Subject: Re: [php] getting download resume to work 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? >>>>>>>ANS: not really as of yet, but, there will be as I will be restricting downloads to authenticated users... > set_time_limit(0); > $file=$_REQUEST['file']; > $extstart=strpos($file, "."); What does $extstart contain now? >>>>>>>ANS: just the first part of the name, before the extension, (for no reason) > $ext=substr($file, $extstart+1); So $ext is now a piece of the file. Why? >>>>>>>ANS: this is done so that I can set the ==header("Content-Type: application/".$ext);== > $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). >>>>>>>ANS: correct > if(isset($_ENV['HTTP_RANGE'])) { > list($a, $range)=explode("=",$_ENV['HTTP_RANGE']); So $a is now bytes, and $range is something like 123-456 >>>>>>>ANS: partly correct, what I receive is =="Range: bytes=14232-"== it has no last number. > str_replace($range, "-", $range); This makes no sense. The range requested is bytes 123 through 456, and you're converting this to 123456. Why? >>>>>>>ANS: when I left it on what it would send to the browser would be =="header("Content-Range: 123--456/457");"== (it would tack on an extra dash symbol (-) and the browser did not understand it) > $size2=$size-1; > header("Content-Range: $range$size2/$size"); > $new_length=$size2-$range; This will definitely not work, based on my comments above. >>>>>>>ANS: it appears to work enough that FlashGet will try to recover/resume and it completes, but, the byte count is always off by around 1 or so bytes and I cannot figure out why... 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. >>>>>>>ANS: I have set it to log to a text file previously and it is always 1 byte different. I am at a total loss as to where it is happening, I will attach the the log files that I have been pouring over as well the actual script to you... Hope that helps. Chris ===== Become a better Web developer with the HTTP Developer's Handbook http://httphandbook.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|||
|
got it to work using fseek,
feel like a bozo posting this when it was my lack of thinking in the first place as to why it didn't work. thanks all for the help... Scott "Chris Shiflett" <shiflett@php.net> wrote in message news:20030912032127.42923.qmail@web14301.mail.yaho o.com... > 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/ |