473,386 Members | 1,785 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.

fopen, fpassthru downloading

hello all

im looking to make a download script as i cannot use the .htaccess to
control directory access to files as im using a php login system using
mysql and sessions.

i have been playing about with fopen and fpassthru but having a few
problems making the file download. The files involved would mainly be
but not limited to .pdfs, .docs and .zips

i have created the following:

$filepath = '/home/me/folder/file.zip';
$size = filesize($filepath);

header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=download.zip");
header("Content-Length: ".$size);

$ok = fopen($filepath, 'rb');
fpassthru($ok);
this pops up the download box and downloads in firefox, but in ie it
pops up the box and then fails. any ideas?

im guessing its something else that i need to put into my headers but
i've no idea what. i've been playing with cache and the mime type but
this seems to download still in firefox but display the text version of
the zip file in the window in ie.

Thanks for any advice.
Jul 17 '05 #1
6 4799
Steve wrote:
hello all

im looking to make a download script as i cannot use the .htaccess to
control directory access to files as im using a php login system using
mysql and sessions.

i have been playing about with fopen and fpassthru but having a few
problems making the file download. The files involved would mainly be
but not limited to .pdfs, .docs and .zips

i have created the following:

$filepath = '/home/me/folder/file.zip';
$size = filesize($filepath);

header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=download.zip");
header("Content-Length: ".$size);

$ok = fopen($filepath, 'rb');
fpassthru($ok);
this pops up the download box and downloads in firefox, but in ie it
pops up the box and then fails. any ideas?

im guessing its something else that i need to put into my headers but
i've no idea what. i've been playing with cache and the mime type but
this seems to download still in firefox but display the text version of
the zip file in the window in ie.

Thanks for any advice.


I've done with before with almost exactly the same set of headers and
mine works just fine. The only difference being that I use

Content-Type: application/force-download;
instead of your
Content-Type: application/octet-stream;

I know all modern user-agents (including IE) support this type but I
haven't tested it on old browsers.

Jul 17 '05 #2
Terence wrote:

I've done with before with almost exactly the same set of headers and
mine works just fine. The only difference being that I use

Content-Type: application/force-download;
instead of your
Content-Type: application/octet-stream;

I know all modern user-agents (including IE) support this type but I
haven't tested it on old browsers.

thanks for your reply, still no luck though

it seems as though every header i try seems to work in firefox but
nothing works in ie, even a combination of headers.

at the moment with:

header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"download.zip\"");
header("Content-Length: ".$size);

it trys to download the actual php file instead, and then fails if i
proceed. this is really confusing because reading around, others have
experienced success with similar headers.
Jul 17 '05 #3
With total disregard for any kind of safety measures Steve
<ki*******@hotmail.com> leapt forth and uttered:
it seems as though every header i try seems to work in firefox
but nothing works in ie, even a combination of headers.


IE is known for it's quirky and often deliberatly contrary handling
of MIME types. Most of the times it seems to guess the MIME type from
the originating file header rather than listening to the info that
the server gives it...

--
Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/
Jul 17 '05 #4
Phil Roberts wrote:
With total disregard for any kind of safety measures Steve
<ki*******@hotmail.com> leapt forth and uttered:

it seems as though every header i try seems to work in firefox
but nothing works in ie, even a combination of headers.

IE is known for it's quirky and often deliberatly contrary handling
of MIME types. Most of the times it seems to guess the MIME type from
the originating file header rather than listening to the info that
the server gives it...

it sure does

i've found a solution albeit unsatisfactory. the script has to be called
via a link into a new window rather than through the address bar
directly.... if only i knew that 8 hours ago when i was having problems :)
Jul 17 '05 #5
"Steve" <ki*******@hotmail.com> wrote in message
news:pL*********************@stones.force9.net...
i've found a solution albeit unsatisfactory. the script has to be called
via a link into a new window rather than through the address bar
directly.... if only i knew that 8 hours ago when i was having problems :)


The best solution would be to use Apache rewrite, so that the browser thinks
it's downloading a file in the normal fashion. Worth looking into.
Jul 17 '05 #6
"Chung Leong" <ch***********@hotmail.com> wrote in message news:<Sd********************@comcast.com>...
"Steve" <ki*******@hotmail.com> wrote in message
news:pL*********************@stones.force9.net...
i've found a solution albeit unsatisfactory. the script has to be called
via a link into a new window rather than through the address bar
directly.... if only i knew that 8 hours ago when i was having problems :)


The best solution would be to use Apache rewrite, so that the browser thinks
it's downloading a file in the normal fashion. Worth looking into.


I'm skeptical, how the mod_rewrite will help here. The OP says
about the problem with downloading zip files via script--which we have
discussed here many times. The download script should be called via
clicking the link; if it is called directly from browser, it will
display the binary output.

--
http://www.sendmetoindia.com - Send Me to India!
Email: rrjanbiah-at-Y!com
Jul 17 '05 #7

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

Similar topics

7
by: Phil Powell | last post by:
I have a PHP script that would read in a binary file and display it as if it were <img src>, how would you do that w/o changing the header's MIME type? The entire file does not need to be changed....
3
by: theouimets | last post by:
Is there a limit to how long a URL can be with fopen? I have a very long URL as there are lots of things to be passed some variables and some XML. It seems to get to a certain point and then...
12
by: Bill | last post by:
For my personal use I am accessing a railway timetable page, parsing its contents and then sending brief relevant information as the subject line of an email to be read on a mobile phone. The...
1
by: Michael Ferrier | last post by:
Hi, I've used fopen() extensively to open web pages. I've found that there is a small minority of web pages that open fine in a browser, but are inaccessible using fopen(). Here are two such...
7
by: git_cs | last post by:
Hey, guys and gals Somedays ago, I had asked for the DES algorithm in C language. Although I have written the algorthim in C myself, I am facing a peculiar problem, which I hope some of u guys and...
13
by: Blue | last post by:
Hi , Can any one please let me explain me the diffrences between "open"/ "fopen" or "read"/"fread" or "write/fwrite". I know that "open" /"read" / "write" are system calls and "fopen"...
185
by: Martin Jørgensen | last post by:
Hi, Consider: ------------ char stringinput ..bla. bla. bla. do {
10
by: Julia | last post by:
Hi, there, I am trying to append a binary file by using: FILE *strean; stream = fopen( "c:\temp.dat", "ba+" )); Is there a way that I can check if the file exists or not before fopen,...
1
by: gezerpunta | last post by:
Hi I need to fetch lobs with php script. I found it but there is an error. $stmt = $db->prepare("select * from test where oid = 17056"); $stmt->execute(); $stmt->bindColumn('oid', $lob,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.