Connecting Tech Pros Worldwide Help | Site Map

Force download WITHOUT readfile?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 05:43 AM
Matthew Sims
Guest
 
Posts: n/a
Default Force download WITHOUT readfile?

Is it possible to force a download without using the readfile
function?

My website setup consists of my server that serves the web pages plus
a high-speed file server elsewhere on the internet that servers my
files. I'm currently using header("Location: abc.com") to redirect my
users to this other site but can't force a download.

I can get it to work using readfile() but that means the file moves
from the high-speed server through my webserver and then to the user,
which I don't want.

Here's my current setup:

header("Content-Type:application/force-download;name=\"".$path_parts["basename"]."\"");
header("Content-Disposition:attachment;filename=\"".$path_parts["basename"]."\"");
header("Content-Length: $size");
header("Content-Transfer-Encoding: binary");
header("Location: ".$path["path"]."");

The above works just fine but doesn't force the download. Changing the
header("Location: ".$path["path"]."") to readfile($path["path"])
forces the download but now the file moves through my webserver and I
don't want that.

Thanks

--Matt

  #2  
Old July 17th, 2005, 05:43 AM
Tim Van Wassenhove
Guest
 
Posts: n/a
Default Re: Force download WITHOUT readfile?

In article <1e963607.0406090810.221327e3@posting.google.com >, Matthew Sims wrote:[color=blue]
> Is it possible to force a download without using the readfile
> function?[/color]

You tell me, is there another way than a UserAgent that downloads file(s)?
[color=blue]
> My website setup consists of my server that serves the web pages plus
> a high-speed file server elsewhere on the internet that servers my
> files. I'm currently using header("Location: abc.com") to redirect my
> users to this other site but can't force a download.[/color]

Oh, your going to play with the Content-type... This has been discussed
many times before in this group. So i'm pretty sure you'll find out why
it's impossible by definition.
[color=blue]
> I can get it to work using readfile() but that means the file moves
> from the high-speed server through my webserver and then to the user,
> which I don't want.
>
> Here's my current setup:
>
> header("Content-Type:application/force-download;name=\"".$path_parts["basename"]."\"");
> header("Content-Disposition:attachment;filename=\"".$path_parts["basename"]."\"");
> header("Content-Length: $size");
> header("Content-Transfer-Encoding: binary");
> header("Location: ".$path["path"]."");[/color]

On the first site, you redirect them, not directly to the file, but to a
download.php on the second server.

On the second server you place your download.php that outputs the
headers and the readfile...


--
Tim Van Wassenhove <http://home.mysth.be/~timvw/contact.php>
  #3  
Old July 17th, 2005, 05:44 AM
Matthew Sims
Guest
 
Posts: n/a
Default Re: Force download WITHOUT readfile?

> > My website setup consists of my server that serves the web pages plus[color=blue][color=green]
> > a high-speed file server elsewhere on the internet that servers my
> > files. I'm currently using header("Location: abc.com") to redirect my
> > users to this other site but can't force a download.[/color]
>
> Oh, your going to play with the Content-type... This has been discussed
> many times before in this group. So i'm pretty sure you'll find out why
> it's impossible by definition.[/color]

I did scour the entire group and though everyone's answer was to use
readfile, no one specifically said that there is no other way. So I
guess this post is basically the "there's no other way" post.
[color=blue]
>[color=green]
> > I can get it to work using readfile() but that means the file moves
> > from the high-speed server through my webserver and then to the user,
> > which I don't want.
> >
> > Here's my current setup:
> >
> > header("Content-Type:application/force-download;name=\"".$path_parts["basename"]."\"");
> > header("Content-Disposition:attachment;filename=\"".$path_parts["basename"]."\"");
> > header("Content-Length: $size");
> > header("Content-Transfer-Encoding: binary");
> > header("Location: ".$path["path"]."");[/color]
>
> On the first site, you redirect them, not directly to the file, but to a
> download.php on the second server.
>
> On the second server you place your download.php that outputs the
> headers and the readfile...[/color]

Yeah, that's pretty much what I thought. Unfortunately, the second
server is commercially owned which means I have little input
configuration-wise. So I guess I'm stuck with a redirect.

Thanks anyway

--Matt
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.