Netscape downloading with a .php extension added on to file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ryan Frank
Forum Newbie
Posts: 2
Joined: Wed Feb 18, 2004 3:50 pm

Netscape downloading with a .php extension added on to file

Post by Ryan Frank »

<?
session_start();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: text/comma-separated-values");
header("Content-Disposition: attachment; filename=\"results.csv\"");

$i = $_SESSION['allresults_count'];
$array = $_SESSION['allresults'];
$a = 0;

echo("Rec Number,Sales,Employees,Sic,Sic extention,Name,State,Zip,Zip extention,County,Census Tract,Bank Fimp,Branch\n");
while($a < $i)
{
reset($array[$a]);
while(list($key, $val) = each($array[$a]))
{
echo('="' . $val . '"');
echo(",");
}
echo("\n");
$a++;
}
?>


I'm using this to generate a .cvs file on the fly to be downloaded from data collected in $_SESSION['allresults'].... IE handles it fine, but netscape wants to add a .php so it becomes results.cvs.php... I am using the same set of headers as I use for downloading .xls files (obviously Content-Type is different, but otherwise the same) so I was wondering if anyone knew what is causing this.
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

I use this in my header:

Code: Select all

<?php
header("Content-type: application/octet-stream"); 
header("Content-Disposition: attachment; filename=page_name.csv"); 
header("Content-Transfer-Encoding: binary"); 
?>
I have no ''s or "'s around my page name

Does this make a difference ?
Ryan Frank
Forum Newbie
Posts: 2
Joined: Wed Feb 18, 2004 3:50 pm

Post by Ryan Frank »

Doesnt appear to do anything.... thanks for the reply though.

Netscape is definately getting the content-type correctly as the dialog box says "result.cvs.php is of type text/comma-separated-values (or application/octet-stream if i use that) but still insists on adding .php to the filename.... still confused as why it works when the content-type is for ms .xls files.
Post Reply