For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > November 2004 > header() for download - pb in ns7









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author header() for download - pb in ns7
Daedalus

2004-11-23, 3:56 am

Hi, I have made a php page where people can configure a javascript online
with a preview and then dowload the result. Here is the code:
<?
// Some code that create a temp file ($file handler = $fd) and write the
script

// Send the file
header("content-type: text/plain");
header("Content-length: ".filesize($file));
header('Content-Disposition: attachment; filename="script_name.js"');
flush();
while(!feof($fd)){
echo fread($fd, 1024);
flush();
}
fclose($fd);
?>

Everything works fine with IE, Mozilla, FireFox and Opera. But with Netscape
(7.0) no file is sent and I end up with a blank page. But still with
Netscape, if I right-click the link and choose save as..., then it works ok
Any idea ?

Thanks
Dae


Daedalus

2004-11-23, 8:56 am

Looks like Netscape (at least 7.0) don't want to download text/plain even
with attachment specified.


> Hi, I have made a php page where people can configure a javascript online
> with a preview and then dowload the result. Here is the code:
> <?
> // Some code that create a temp file ($file handler = $fd) and write the
> script
>
> // Send the file
> header("content-type: text/plain");
> header("Content-length: ".filesize($file));
> header('Content-Disposition: attachment; filename="script_name.js"');
> flush();
> while(!feof($fd)){
> echo fread($fd, 1024);
> flush();
> }
> fclose($fd);
> ?>
>
> Everything works fine with IE, Mozilla, FireFox and Opera. But with

Netscape
> (7.0) no file is sent and I end up with a blank page. But still with
> Netscape, if I right-click the link and choose save as..., then it works

ok
> Any idea ?
>
> Thanks
> Dae



Hilarion

2004-11-23, 3:56 pm

Have you tried specifying different MIME type? Eg. "text/javascript" ?

Hilarion


Daedalus

2004-11-23, 3:56 pm


"Hilarion" <hilarion@SPAM.op.SMIECI.pl> wrote in message
news:cnvc3n$d9e$1@news.onet.pl...
> Have you tried specifying different MIME type? Eg. "text/javascript" ?


Yes I tried. But actually I already solved my problem, I just forgot to post
my solution here;
So "text/plain", "text/javascript" and "application/x-javascript" behave the
same way: printing the content of the file in the browser (Netscape 7).
I finally used "application/octet-stream" to force NS to download it. Only
problem is that without some setting changes NS always try to save the file
as script_name.js.php. Anyway most people will just remove the php extension
and even if they don't the script will work with the php extension.

Dae


R. Rajesh Jeba Anbiah

2004-11-23, 3:56 pm

"Daedalus" <arsenault.daniel@videotron.ca> wrote in message news:<30grsoF2vaomvU1@uni-berlin.de>...
> "Hilarion" <hilarion@SPAM.op.SMIECI.pl> wrote in message
> news:cnvc3n$d9e$1@news.onet.pl...
>
> Yes I tried. But actually I already solved my problem, I just forgot to post
> my solution here;
> So "text/plain", "text/javascript" and "application/x-javascript" behave the
> same way: printing the content of the file in the browser (Netscape 7).
> I finally used "application/octet-stream" to force NS to download it. Only
> problem is that without some setting changes NS always try to save the file
> as script_name.js.php. Anyway most people will just remove the php extension
> and even if they don't the script will work with the php extension.


You may want to look at the usernotes section of
<http://in2.php.net/header> Each browser requires different headers.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com
Daedalus

2004-11-23, 8:55 pm

> You may want to look at the usernotes section of
> <http://in2.php.net/header> Each browser requires different headers.
>
> --
> <?php echo 'Just another PHP saint'; ?>
> Email: rrjanbiah-at-Y!com


Yes I've already look there (including the user notes). And AFAIK browsers
do not really require different headers, but they may behave differently
with some headers (mostly the non HTTP1.1 standard headers like
Content-Disposition). This is "AFAIK". Anyone, feel free to correct me.

Dae


J.O. Aho

2004-11-23, 8:55 pm

Daedalus wrote:
> Hi, I have made a php page where people can configure a javascript online
> with a preview and then dowload the result.
> Everything works fine with IE, Mozilla, FireFox and Opera. But with Netscape
> (7.0) no file is sent and I end up with a blank page. But still with
> Netscape, if I right-click the link and choose save as..., then it works ok


I guess it has to do whit some content-type detections in Netscape (based on
mozilla 1.0.1 if I remeber it right), I would make a browser type check and if
it detects Netscape 7.0, then use another content-type, this is how things
like this are usually solved in MSIE when it don't want to work.


//Aho
R. Rajesh Jeba Anbiah

2004-11-24, 3:56 am

"Daedalus" <arsenault.daniel@videotron.ca> wrote in message news:<30hkjhF2unq30U1@uni-berlin.de>...
>
> Yes I've already look there (including the user notes). And AFAIK browsers
> do not really require different headers, but they may behave differently
> with some headers (mostly the non HTTP1.1 standard headers like
> Content-Disposition). This is "AFAIK". Anyone, feel free to correct me.


Sorry, didn't mean all the headers; but to force download...
<http://in.php.net/header#21708> and
<http://cvs.sourceforge.net/viewcvs.....17&view=markup>
(search for "// Download").

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com