473,324 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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

Jul 17 '05 #1
2 2719
Bryan Feeney wrote:
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?


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']
Jul 17 '05 #2
"Bryan Feeney" <bf*****@oceanfree.net> wrote in message news:<2i************@uni-berlin.de>...
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?


<?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
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dan Gass | last post by:
The difflib.py module and the diff.py tools script in Python 2.4 alpha 3 now support generating side by side (with intra line differences) in HTML format. I have found this useful for performing...
6
by: vasilijepetkovic | last post by:
Hello All, I have a problem with the program that should generate x number of txt files (x is the number of records in the file datafile.txt). Once I execute the program (see below) only one...
2
by: google.groups.tr | last post by:
I have an Access 97 database that has a routine to generate a unique report as a PDF file and email it to one person, and loops about 300 times. Each instance through the loop uses a registry...
6
by: Alan Krueger | last post by:
Is there a way to automatically include C# files (.cs) generated by a third-party tool into a Visual C# .NET build? It's possible the set of files generated by this tool might change. Adding...
3
by: daniele.balducci | last post by:
Hi All, I'm generating XLS files from ASP(.Net) code using the usual code chunks ... Response.ContentType = "application/vnd.ms-excel" Response.AppendHeader("Content-Disposition", "attachment;...
1
by: Xah Lee | last post by:
The following is a program to generate thumbnail images for a website. Useful, if you want to do that. It is used to generate the thumbnails for my “Banners, Damsels, and Mores” project...
1
by: Nathan Sokalski | last post by:
Visual Studio 2005 recently stopped generating the *.designer.vb files for my *.aspx and *.ascx files. I am using Service Pack 1, and do not believe I did anything differently than normal prior to...
10
by: lancer6238 | last post by:
Hi all, I'm having programs reading from files. I have a text file "files.txt" that contains the names of the files to be opened, i.e. the contents of files.txt are Homo_sapiens.fa...
2
by: Draggonn | last post by:
Hello all. I'm not sure if this is the right part of the forum to ask, but I couldn't find any better place. I am trying to make a program that will take a file of any extension, and split it into...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.