Connecting Tech Pros Worldwide Forums | Help | Site Map

header() for download - pb in ns7

Daedalus
Guest
 
Posts: n/a
#1: Jul 17 '05
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
Guest
 
Posts: n/a
#2: Jul 17 '05

re: header() for download - pb in ns7


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

[color=blue]
> 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[/color]
Netscape[color=blue]
> (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[/color]
ok[color=blue]
> Any idea ?
>
> Thanks
> Dae[/color]


Hilarion
Guest
 
Posts: n/a
#3: Jul 17 '05

re: header() for download - pb in ns7


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

Hilarion


Daedalus
Guest
 
Posts: n/a
#4: Jul 17 '05

re: header() for download - pb in ns7



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

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
Guest
 
Posts: n/a
#5: Jul 17 '05

re: header() for download - pb in ns7


"Daedalus" <arsenault.daniel@videotron.ca> wrote in message news:<30grsoF2vaomvU1@uni-berlin.de>...[color=blue]
> "Hilarion" <hilarion@SPAM.op.SMIECI.pl> wrote in message
> news:cnvc3n$d9e$1@news.onet.pl...[color=green]
> > Have you tried specifying different MIME type? Eg. "text/javascript" ?[/color]
>
> 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.[/color]

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
Guest
 
Posts: n/a
#6: Jul 17 '05

re: header() for download - pb in ns7


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

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
Guest
 
Posts: n/a
#7: Jul 17 '05

re: header() for download - pb in ns7


Daedalus wrote:[color=blue]
> 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[/color]

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
Guest
 
Posts: n/a
#8: Jul 17 '05

re: header() for download - pb in ns7


"Daedalus" <arsenault.daniel@videotron.ca> wrote in message news:<30hkjhF2unq30U1@uni-berlin.de>...[color=blue][color=green]
> > You may want to look at the usernotes section of
> > <http://in2.php.net/header> Each browser requires different headers.[/color]
>
> 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.[/color]

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

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


Similar PHP bytes