Need "Resume Support" in forced downloding of medi

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Irfan12
Forum Newbie
Posts: 2
Joined: Wed Sep 19, 2007 4:30 pm

Need "Resume Support" in forced downloding of medi

Post 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]
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

php will not give you that

Post 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.
ReDucTor
Forum Commoner
Posts: 90
Joined: Thu Aug 15, 2002 6:13 am

Post 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.
Last edited by ReDucTor on Wed Sep 19, 2007 11:15 pm, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

It might also be $_SERVER['HTTP_RANGE'].
(#10850)
ReDucTor
Forum Commoner
Posts: 90
Joined: Thu Aug 15, 2002 6:13 am

Post by ReDucTor »

actually it would only be $_SERVER['HTTP_RANGE'], my bad.
Irfan12
Forum Newbie
Posts: 2
Joined: Wed Sep 19, 2007 4:30 pm

Need "Resume Support" in forced downloding of medi

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
Post Reply