473,385 Members | 1,645 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,385 software developers and data experts.

Adding filename to downloaded file

Hi,

I'm using php to generate a csv file and want to force the user to
download it to their local PC.

Trouble is, when I use:

header("Content-Disposition: attachment; filename=\"download.csv\"");

the browser wants to save the file as download.csv.php

Any suggestions as to how I can get rid of the .php? I'd rather not tell
apache that it should pass csv files through php.

Thanks,

Russell.

Jul 17 '05 #1
3 6076
Russell <nu**@null.noemail> wrote in message news:<xk*****************@news-binary.blueyonder.co.uk>...
Hi,

I'm using php to generate a csv file and want to force the user to
download it to their local PC.

Trouble is, when I use:

header("Content-Disposition: attachment; filename=\"download.csv\"");

the browser wants to save the file as download.csv.php

Any suggestions as to how I can get rid of the .php? I'd rather not tell
apache that it should pass csv files through php.


IE needs specific headers. Always refer manual before posting any
questions http://in.php.net/header

<?php
$file_name = 'xx.csv';
header('Content-Type: text/comma-separated-values');
//IE need specific header...
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');
}
?>
---
"Dying is an art, like everything else"---Sylvia Plath
Email: rrjanbiah-at-Y!com
Jul 17 '05 #2
R. Rajesh Jeba Anbiah wrote:
Russell [wrote]:
I'm using php to generate a csv file and want to force the user to [...]

There is no "force", despite what Skywalker'd have you believe.
header('Content-Type: text/comma-separated-values');


Perhaps the MIME media type text/x-comma-separated-values or perhaps
text/x-csv or perhaps something else prefixed with "x-"; there is no
text/comma-separated-values registered though.
Jul 17 '05 #3
Is the operation going to the PHP page in question a POST or a GET? I
have run into problems with IE before using a POST to launch a
download.

Try adding this line:

header("Content-type: application/octet-stream");

Also.

Russell <nu**@null.noemail> wrote in message news:<xk*****************@news-binary.blueyonder.co.uk>...
Hi,

I'm using php to generate a csv file and want to force the user to
download it to their local PC.

Trouble is, when I use:

header("Content-Disposition: attachment; filename=\"download.csv\"");

the browser wants to save the file as download.csv.php

Any suggestions as to how I can get rid of the .php? I'd rather not tell
apache that it should pass csv files through php.

Thanks,

Russell.

Jul 17 '05 #4

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

Similar topics

7
by: Kornelius Finkenbein | last post by:
Hello folks! I've got a strange problem with my download-script in conjunction with M$ internet explorer, if the filename I want to link to includes more than one points. In Netscape the problem...
7
by: deko | last post by:
I need to allow users to download files from a directory that is not publicly accessible. To do this, I use a download script: header("Content-Type: application/octet-stream");...
7
by: J1C | last post by:
How could I create a random filename for a single-use download? So, if a user was to download a file from a site it would send them a unique filename that could only be used once. That link would...
0
by: Michael Probst | last post by:
Hi all, I am new to .NET and the way XML data is handled in .NET I wrote a small application with .NET forms in C++ The application reads data from an XML file to fill-in the fields of the...
2
by: Bob Weiner | last post by:
Can I control the name of a file downloaded if that file name isn't in a request header? I have a data grid that contains a list of excel files by date. In each row there is a ButtonColumn...
2
by: rudderstick | last post by:
Hi there all, I have an interesting problem.... I work for a company that develops software for the building industry and would like to distribute one of our software products via the web. ...
10
by: dudeishfish | last post by:
Hey Everyone! After using Devshed (possibly the worst forum I have ever encountered) I have come here with my questions and answers about Java, Python, VB, Basic C++, HTML, Game Maker, and...
0
by: NatsoumiMaya | last post by:
hi ppl, i have a code to write in C where i have to implement the mkdir, rm, rmdir and touch functions using double linked lists...im haveing trouble with it...here is what i have so far: #ifndef...
2
by: ScottM | last post by:
Hi, I am an experienced VB6 programmer but a novice when it comes to MS Access. I have a form for ECO's (Engineering Change Orders) based on the table ECO, and in it I created a subform that is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.