Page 1 of 1

Need "Resume Support" in forced downloding of medi

Posted: Wed Sep 19, 2007 4:34 pm
by Irfan12
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am using the following PHP code to force the internet browser to download a media file(e.g, .mp3, .wma), But in this code, there is no resume support in downloading these files.
i dont know PHP, i am very much thankful to the person who gave me this code.
Kindly tell me, that what changings are to be needed to enable resume support in downloading. I am using linux webserver.
Thankyou.


Code: ( php )

Code: Select all

<?php
 
if((array_key_exists('file', $_GET)) && ($fp = @fopen($_GET['file'], 'rb')) && (pathinfo($_GET['file'], PATHINFO_EXTENSION) != 'php'))
{
    header('Content-Disposition: attachment; filename="' . basename($_REQUEST['file']) . '";' );
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' . filesize($_GET['file']));
    fpassthru($fp);
}
else
{
?><html>
    <head>
        <title>404 - File not found</title>
    </head>
    <body>
        <div style="font-size:36px;">File not found</div>
        <div style="font-size:12px;">The file you requested ('<?php echo $_GET['file'] ?>') could not be found.</div>
    </body>
</html><?php
}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]1.[/b] Select the correct board for your query. Take some time to read the guidelines in the sticky topic.[/quote]

php will not give you that

Posted: Wed Sep 19, 2007 8:15 pm
by yacahuma
As far as I know php will not give you that kind of support. In fact after you start downloading it is the responsability of the browser. So php has nothing to do. Maybe you can find a browser plugin for that.

Posted: Wed Sep 19, 2007 8:30 pm
by ReDucTor
You need to send an Accept-Ranges header, e.g.

header('Accept-Ranges: bytes');

Now this will allow the client to send Range HTTP header, which will specify the type it wants to move, common responce for bytes accepted is

Range: bytes=1337-7331

So simply use $_SERVER['HTTP_RANGE'] to fetch the data you want.

Posted: Wed Sep 19, 2007 10:51 pm
by Christopher
It might also be $_SERVER['HTTP_RANGE'].

Posted: Wed Sep 19, 2007 11:15 pm
by ReDucTor
actually it would only be $_SERVER['HTTP_RANGE'], my bad.

Need "Resume Support" in forced downloding of medi

Posted: Thu Sep 20, 2007 4:17 pm
by Irfan12
Thanks for your reply,
As i said that i dont php, So
kindly tell me where should i add your given code to enable resume support
$_SERVER['HTTP_RANGE'],
Thankyou & waiting for your reply

Posted: Thu Sep 20, 2007 4:27 pm
by VladSun

Posted: Thu Sep 20, 2007 6:25 pm
by Christopher
If you look in the PHP.net online manual at the page for the header() function there are some examples in the user section as I recall.