Bluehost.com Web Hosting $6.95

Re: [PHP] getting download resume to work

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 (...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-12-2003
Chris Shiflett
 
Posts: n/a
Default 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?

> 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/
Reply With Quote
  #2 (permalink)  
Old 09-12-2003
Scott Dotson
 
Posts: n/a
Default Re: [PHP] getting download resume to work

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





Reply With Quote
  #3 (permalink)  
Old 09-12-2003
Scott Dotson
 
Posts: n/a
Default Re: [PHP] getting download resume to work

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/

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 02:16 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0