Connecting Tech Pros Worldwide Help | Site Map

Generating CSV files which open correctly in IE

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 05:44 AM
Bryan Feeney
Guest
 
Posts: n/a
Default Generating CSV files which open correctly in IE

I'm working on a site which dynamically generates tables of rates in CSV
format. The script which does the work is called generate_stats.php. Here's
the header

header ("Content-type: application/octet-stream");
header ("Content-Disposition: attachment; filename=query-results.csv");
header ("Pragma: no-cache");
header ("Expires: 0");

Now in Mozilla, the user is correctly asked if they want to save or open a
file called query-results.csv

However in IE5 the user is asked if they want to open or save a file called
generate_stats.php.
If they open they're then asked if they want to open or save a file called
query-results.csv.

Does anyone know how I can arrange for IE to immediately open a file called
query-results.csv?

Thanks
--
Bryan




  #2  
Old July 17th, 2005, 05:44 AM
Kevin Thorpe
Guest
 
Posts: n/a
Default Re: Generating CSV files which open correctly in IE

Bryan Feeney wrote:[color=blue]
> I'm working on a site which dynamically generates tables of rates in CSV
> format. The script which does the work is called generate_stats.php. Here's
> the header
>
> header ("Content-type: application/octet-stream");
> header ("Content-Disposition: attachment; filename=query-results.csv");
> header ("Pragma: no-cache");
> header ("Expires: 0");
>
> Now in Mozilla, the user is correctly asked if they want to save or open a
> file called query-results.csv
>
> However in IE5 the user is asked if they want to open or save a file called
> generate_stats.php.
> If they open they're then asked if they want to open or save a file called
> query-results.csv.
>
> Does anyone know how I can arrange for IE to immediately open a file called
> query-results.csv?[/color]

IE is braindead (as if you didn't already know that) and defaults to the
script name on saving files totally ignoring the disposition filename.

Link to your script with:
http://www.server.com/generate_stats...ry-results.csv
.... and it might just be able to fathom out what you want it to do. The
server strips off the last part and shoves it in $_SERVER['PATH_INFO']
  #3  
Old July 17th, 2005, 05:44 AM
R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
Default Re: Generating CSV files which open correctly in IE

"Bryan Feeney" <bfeeney@oceanfree.net> wrote in message news:<2iqu0sFq7t6rU1@uni-berlin.de>...[color=blue]
> I'm working on a site which dynamically generates tables of rates in CSV
> format. The script which does the work is called generate_stats.php. Here's
> the header
>
> header ("Content-type: application/octet-stream");
> header ("Content-Disposition: attachment; filename=query-results.csv");
> header ("Pragma: no-cache");
> header ("Expires: 0");
>
> Now in Mozilla, the user is correctly asked if they want to save or open a
> file called query-results.csv
>
> However in IE5 the user is asked if they want to open or save a file called
> generate_stats.php.
> If they open they're then asked if they want to open or save a file called
> query-results.csv.
>
> Does anyone know how I can arrange for IE to immediately open a file called
> query-results.csv?[/color]

<?php
$file_name = 'file.csv';
header('Content-Type: text/x-csv');
// IE need specific header (to show the correct name of downloading file)
// grabbed from phpMyAdmin...
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');
}
//rest...
?>

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.