By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,853 Members | 842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,853 IT Pros & Developers. It's quick & easy.

download-header not working in IE

P: n/a
Hi,

i try to give my script headers so the output text would be downloaded in
the client's browser and not displayed. But it doesn't work at all in my IE
6 and Opera.

<?
header("Content-Type: application/octet-stream");
header("Content-Length: 5");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=\"gamedata.txt\"");

echo "hello";
?>

I have an Apache 1 installed on my system, can it be that it is
misconfigured and sends the headers in a wrong way? How can i change this?

Help please,

bye,
Frank
Jul 17 '05 #1
Share this Question
Share on Google+
18 Replies


P: n/a
What error message do you get?

Also, recall that once the script sends any text, it cannot subsequently
send headers (PHP should complain about this if error reporting is not
turned off).

EE

----- Original Message -----
From: "Frank Thorstens" <Fr************@gmx.de>
Newsgroups: comp.lang.php
Sent: Wednesday, November 05, 2003 6:15 PM
Subject: download-header not working in IE

Hi,

i try to give my script headers so the output text would be downloaded in
the client's browser and not displayed. But it doesn't work at all in my IE 6 and Opera.

<?
header("Content-Type: application/octet-stream");
header("Content-Length: 5");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=\"gamedata.txt\"");

echo "hello";
?>

I have an Apache 1 installed on my system, can it be that it is
misconfigured and sends the headers in a wrong way? How can i change this?
Help please,

bye,
Frank


"Frank Thorstens" <Fr************@gmx.de> wrote in message
news:bo*************@ID-202045.news.uni-berlin.de... Hi,

i try to give my script headers so the output text would be downloaded in
the client's browser and not displayed. But it doesn't work at all in my IE 6 and Opera.

<?
header("Content-Type: application/octet-stream");
header("Content-Length: 5");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=\"gamedata.txt\"");

echo "hello";
?>

I have an Apache 1 installed on my system, can it be that it is
misconfigured and sends the headers in a wrong way? How can i change this?
Help please,

bye,
Frank

Jul 17 '05 #2

P: n/a
"Frank Thorstens" <Fr************@gmx.de> wrote in message news:<bo*************@ID-202045.news.uni-berlin.de>...
Hi,

i try to give my script headers so the output text would be downloaded in
the client's browser and not displayed. But it doesn't work at all in my IE
6 and Opera.

<?
header("Content-Type: application/octet-stream");
header("Content-Length: 5");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=\"gamedata.txt\"");

echo "hello";
?>

I have an Apache 1 installed on my system, can it be that it is
misconfigured and sends the headers in a wrong way? How can i change this?

Help please,


IE needs special headers. Read the notes at
http://in.php.net/header

<?php

header('Content-Type: XXXXXXXXXXXXXX');
//IE need specific header
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
{
header('Content-Disposition: inline; filename="'.$file_name.'"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
}
else
{
header('Content-Disposition: attachment;
filename="'.$file_name.'"');
header('Pragma: no-cache');
}
?>
---
"The world is too dangerous to live in—not because of the people who
do evil, but because of the people who sit and let it happen"---Albert
Einstein
Email: rrjanbiah-at-Y!com
Jul 17 '05 #3

P: n/a
Hi,
i try to give my script headers so the output text would be downloaded in the client's browser and not displayed. But it doesn't work at all in
my IE
6 and Opera.

What error message do you get?

Also, recall that once the script sends any text, it cannot subsequently
send headers (PHP should complain about this if error reporting is not
turned off).


I get no error, but it just shows the text in the browser.
I send the headers before any other output.

bye,
Frank
Jul 17 '05 #4

P: n/a
Hi,
i try to give my script headers so the output text would be downloaded in the client's browser and not displayed. But it doesn't work at all in my IE 6 and Opera.

IE needs special headers. Read the notes at
http://in.php.net/header


Thanks, i tried your code but still no luck, the IE just shows the text in
the browser. :-(

bye,
Frank
Jul 17 '05 #5

P: n/a

On 5-Nov-2003, "Frank Thorstens" <Fr************@gmx.de> wrote:
i try to give my script headers so the output text would be downloaded in the client's browser and not displayed. But it doesn't work at all in my IE 6 and Opera.

IE needs special headers. Read the notes at
http://in.php.net/header


Thanks, i tried your code but still no luck, the IE just shows the text in
the browser. :-(


Here's what works for me:
I can't remember where I got it, maybe here. :-)

$filename = $ex_name.'.csv';
$mime_type = 'text/x-csv';
header('Content-Type: ' . $mime_type);
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
if (strpos($_SERVER["HTTP_USER_AGENT"],'MSIE')!==false)
{
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
} else
{
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Pragma: no-cache');
}

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #6

P: n/a
Frank Thorstens wrote:
i try to give my script headers so the output text would be downloaded in
the client's browser and not displayed.


Why?

--
Jock
Jul 17 '05 #7

P: n/a
> > i try to give my script headers so the output text would be downloaded
in
the client's browser and not displayed.


Why?


The client have to open this file in excel. So it's more convinient if he
directly saves the data instead of seeing it in the browser, than have to
save it as text etc.

bye,
Frank
Jul 17 '05 #8

P: n/a
Frank Thorstens wrote:
The client have to open this file in excel. So it's more convinient if he
directly saves the data instead of seeing it in the browser, than have to
save it as text etc.


Why is the client limited to those options?

--
Jock
Jul 17 '05 #9

P: n/a
> > The client have to open this file in excel. So it's more convinient if
he
directly saves the data instead of seeing it in the browser, than have to save it as text etc.


Why is the client limited to those options?


not sure, if I understand your question. The user on the client side wants
to put the downloaded Data into an excel sheet. So it's more convinient if
he directly saves the file and open it in excel.

bye,
Frank
Jul 17 '05 #10

P: n/a
Frank Thorstens wrote:
The user on the client side wants to put the downloaded Data into an excel
sheet.
What format is the data in?
So it's more convinient if he directly saves the file and open it in excel.


If it's an Excel spreadsheet, the registered MIME media type is
application/vnd.ms-excel.

--
Jock
Jul 17 '05 #11

P: n/a
> > The user on the client side wants to put the downloaded Data into an
excel
sheet.

What format is the data in?


it's a comma-separated text file.
The MIME for comma-separeted text files also didn't work. I found out, what
was wrong, see the other post.

but thanks for replying,
Frank
Jul 17 '05 #12

P: n/a
ok, i tested always by putting the URL of the PHP page into the address
field of the browser.
I now found, that the download is initiated by a href to the page or by
other way of linking.

So it seems to work.

Thank all you guys for replying.

bye,
Frank
Jul 17 '05 #13

P: n/a
Frank Thorstens wrote:
it's a comma-separated text file.
The MIME for comma-separeted text files also didn't work.


There is no registered MIME media type for that format. You
might've used text/x-csv or suchlike. Whatever you use, the major
type should be text.

--
Jock
Jul 17 '05 #14

P: n/a
"Frank Thorstens" <Fr************@gmx.de> wrote in message news:<bo*************@ID-202045.news.uni-berlin.de>...
Hi,
i try to give my script headers so the output text would be downloaded in the client's browser and not displayed. But it doesn't work at all in my IE 6 and Opera.

IE needs special headers. Read the notes at
http://in.php.net/header


Thanks, i tried your code but still no luck, the IE just shows the text in
the browser. :-(


In my experience, it won't download if you call it directly.
But, it will work if you call from another script by clicking or by
POST or GET.

---
"The world is too dangerous to live in—not because of the people who
do evil, but because of the people who sit and let it happen"---Albert
Einstein
Email: rrjanbiah-at-Y!com
Jul 17 '05 #15

P: n/a
*** Frank Thorstens wrote/escribió (Thu, 6 Nov 2003 00:15:46 +0100):
i try to give my script headers so the output text would be downloaded in
the client's browser and not displayed. But it doesn't work at all in my IE
6 and Opera.
Your code works for me under Internet Explorer 6. However, it claims it's a
text plain file: IE ignores Content-Type header under certain circumstances
in favour of file extension. That means IE probably makes this a Windows
configuration issue: if you have the "*.txt" file type configured as
"Confirm opening after download" (words might differ, I'm translating from
Spanish) IE will prompt; otherwise, it'll open it inline.

<?
header("Content-Type: application/octet-stream");
header("Content-Length: 5");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=\"gamedata.txt\"");

echo "hello";
?>

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #16

P: n/a
ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) wrote in message news:<ab**************************@posting.google. com>...
"Frank Thorstens" <Fr************@gmx.de> wrote in message news:<bo*************@ID-202045.news.uni-berlin.de>...
Hi,
> i try to give my script headers so the output text would be downloaded in > the client's browser and not displayed. But it doesn't work at all in my IE > 6 and Opera.
IE needs special headers. Read the notes at
http://in.php.net/header


Thanks, i tried your code but still no luck, the IE just shows the text in
the browser. :-(


In my experience, it won't download if you call it directly.
But, it will work if you call from another script by clicking or by
POST or GET.


Frank! Could you please confirm, if it works while calling from
another script or after a POST/GET..

---
"Learn from yesterday, live for today, hope for tomorrow. The
important thing is to not stop questioning."---Albert Einstein
Email: rrjanbiah-at-Y!com
Jul 17 '05 #17

P: n/a
> Frank! Could you please confirm, if it works while calling from
another script or after a POST/GET..


Hi, yes it works, i wrote this as answer to a parallel branch of this
thread. Thanks for your hint!

bye,
Frank
Jul 17 '05 #18

P: n/a
"Frank Thorstens" <Fr************@gmx.de> wrote in message news:<bo*************@ID-202045.news.uni-berlin.de>...
Frank! Could you please confirm, if it works while calling from
another script or after a POST/GET..


Hi, yes it works,


Ok fine. Thanks for acknowledging.

---
"Learn from yesterday, live for today, hope for tomorrow. The
important thing is to not stop questioning."---Albert Einstein
Email: rrjanbiah-at-Y!com
Jul 17 '05 #19

This discussion thread is closed

Replies have been disabled for this discussion.