Professional Web Applications Themes

[PHP] getting download resume to work - PHP Development

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

  1. #1

    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
    [url]http://httphandbook.org/[/url]
    Chris Shiflett Guest

  2. #2

    Default RE: RE: [PHP] getting download resume to work

    All answers are below your questions...
    Thank you for taking the time to p 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:shiflettphp.net]
    Sent: Thursday, September 11, 2003 8:21 PM
    To: Raditha Dissanayake; Scott Dotson; [email]php-generallists.php.net[/email]
    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

    Scott Dotson Guest

  3. #3

    Default Re: [PHP] getting download resume to work

    All answers are below your questions...
    Thank you for taking the time to p 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:shiflettphp.net]
    Sent: Thursday, September 11, 2003 8:21 PM
    To: Raditha Dissanayake; Scott Dotson; [email]php-generallists.php.net[/email]
    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





    Scott Dotson Guest

  4. #4

    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" <shiflettphp.net> wrote in message
    news:20030912032127.42923.qmailweb14301.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
    > [url]http://httphandbook.org/[/url]
    Scott Dotson Guest

Similar Threads

  1. Flash Player 8 Download work-around
    By abrahamchapman in forum Macromedia Flash Player
    Replies: 1
    Last Post: July 31st, 01:25 PM
  2. file download with ftp program does nor work
    By estina in forum Macromedia Contribute General Discussion
    Replies: 0
    Last Post: May 4th, 10:22 AM
  3. Resume Partial Download Help
    By john_kalnin@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 0
    Last Post: April 8th, 02:57 PM
  4. getting download resume to work
    By Scott Dotson in forum PHP Development
    Replies: 0
    Last Post: September 11th, 10:02 PM
  5. Replies: 1
    Last Post: August 28th, 08:14 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139