473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Jul 17 '05 #1
2 5217
In article <1e**************************@posting.google.com >, Matthew Sims wrote:
Is it possible to force a download without using the readfile
function?
You tell me, is there another way than a UserAgent that downloads file(s)?
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.
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.
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"]."");


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>
Jul 17 '05 #2
> > 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.
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.


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.
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"]."");


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


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
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: peetm | last post by:
I'd like to write to a log whenever a visitor to my site downloads a file. So, I'd like the link they click to be to a php 'page' that returns the file. Don't know how to do that! Side...
11
by: Jim Willsher | last post by:
Hi all, PHP 4.2.2 on RedHat9 I have some files on my website for people to download, and I want to generate the file location "on the fly", so the URL is held in a database. I have a simple...
4
by: Kevin Muenzler, WB5RUE | last post by:
How do I force a browser to download a file instead of displaying it? In other words I have a page with MP3 and WMA files on it and I would like for the visitor to download the file instead of...
4
by: C16 | last post by:
Hi All I have a simple download script for files on my website and I use the code below to download the files: $fp = fopen($filename, "rb"); if ( $fp ) { $filesize = $file;
2
by: comp.lang.php | last post by:
class ReportGenerator { function ReportGenerator() {} /** * Generate the HTTP headers necessary for this file type. Can be called statically *
1
by: abureach | last post by:
Hi, I cant able to direcly open the file in IE(force download) the follwing code is not working in IE. Please help me my coding is if(ini_get('zlib.output_compression'))
0
by: jinnareddy | last post by:
Hi, I'm unable to download a file that is having a 2-byte char in its name (e.g.テ) using force download option. Though, am able to download file names involving ASCII chars. I have tried URL...
2
by: Dan D | last post by:
I have a large install file (an exe) on my web server that people download and install from. Looking at my log files, I see a lot of people downloading it, but no way to tell for sure if they...
0
by: ridgedale | last post by:
Does anyone know how I can prevent the Acrobat Reader plugin from loading a pdf into the web browser? I need to force the user to download the pdf file and run the pdf using the full Adobe Acrobat...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.