Closed
Bug 205868
Opened 22 years ago
Closed 22 years ago
The download of a php-script generated csv-file is saved with the additional file extension '.php'; as filename.csv.php.
Categories
(Core Graveyard :: File Handling, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: chayes, Assigned: law)
References
()
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4a) Gecko/20030403 Phoenix/0.5
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4a) Gecko/20030403 Phoenix/0.5
My impression is that Mozilla for some reason takes the extension of the script
that makes this file as the file type.
Reproducible: Always
Steps to Reproduce:
1. Go http://www.sense.nl/bug.html
2. Left-click the link: a php script file (bug.php) now invokes a file download.
3. Choose to save the file.
Actual Results:
When saving the file, Mozilla (and Phoenix) do use the offered filename for
saving, but also recognize the file as type *.PHP.
As a result the file is saved as example.csv.php. :(
Choosing file type 'All" in the save dialog does not change the behavior.
Expected Results:
Save with the given filename example.csv, not adding .php.
The relevant lines of the php script (note: ."\n" adds a newline to the string)
:
<?PHP
header("Content-type: text/csv\n");
header('Content-Disposition: attachment; filename="example.csv"'."\n");
echo "1,2,3,4,5\n6,7,8,9,10";
exit;
?>
This script results in this:
--------
Content-type: text/csv
Content-Disposition: attachment; filename="example.csv"
"bla1","bla2","bla3"
"bla4","bla5","bla6"
"bla7","bla8","bla9"
--------
Every line has a newline at the end. I guess of the 0A0D type .
It also happens with a slightly modded header:
Content-Disposition: inline; filename="example.csv"
It also happens in phoenix 0.5:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4a) Gecko/20030403 Phoenix/0.5
But not in
Opera Version 6.05 Build 1140
IE 6.0
Odd: renaming the file slightly, e.g. exsample.csv, gives the desired result.
Somehow related bug reports:
181029 chimera adds .txt to a file without being asked
146781 download file misnaming, when the downloaded file comes from a redirected
URL [extension]
120327 Sanitize extension-fixup code: Don't add .exe or .txt to files names of
text/plain and application/octet-stream, etc. (dead bug)
181727 Files downloaded with incorrect extensions should have correct extension
appended to the end.
Duplicate of Bug 65827
In the meantime, see the workarounds here:
http://www.php.net/header/
Search downward to read the 2 posts on "Mozilla".
Note, both those \n are not needed and should be removed.
![]() |
Reporter | |
Comment 2•22 years ago
|
||
1) Thanks kitchin2, but the solutions mentioned there are specifically for MS
Word or zipped files. Adding a zip or doc extension is not helping...
2) If unclear: the remark in the report on changing the filename ('odd:') was
not about the filename i give in the script, but about the save-dialog.
Maybe it is just that Mozilla needs to recognize what to do with text/csv ?
![]() |
Reporter | |
Comment 3•22 years ago
|
||
It is very related to Bug 65827 but not exactly the same.
Anyway i will instruct users to use 'save target' as this DOES work.
For debuggers - maybe it has to do with this part in components/nsHelperAppDlg.js
(line 115/116 in my version of Firebird 0.6)
// promptForSaveToFile: Display file picker dialog and return selected file.
promptForSaveToFile: function(aContext, aDefaultFile, aSuggestedFileExtension)
I suspect the function call's 'aSuggestedFileExtension', but i cannot find the
function call.
<?php
// $type= 'unknown/nothing'; // a hack used to prevent filename guessing
// $type= 'application/vnd.ms-excel'; // may load in excel?
// $type= 'text/csv'; // firebird tries rename it?
$type= 'text/comma-separated-values'; // common, works for me
header('Content-Disposition: attachment; filename="example.csv"');
header("Content-Type: $type");
?>
![]() |
Reporter | |
Comment 6•22 years ago
|
||
They are very related indeed.
In both cases a server script (e.g. serverscript.php or ~.cgi) proposes a
filename (e.g. filename.csv) in a header.
This bug says: the save dialog adds .php to the filename as given in the header,
so tries to save as "filename.csv.php".
Bug 65827 says: the save dialog uses the script name (e.g. serverfile.cgi) as
filename, so "serverscript.cgi".
I think for debuggers it is good to recognize this difference, it may help in
finding the cause.
BTW kitchin2: I tried your suggestion: did not solve it. Try
http://www.sense.nl/bug.html
Please if you try, tell how the file is saved on your system.
Comment 7•22 years ago
|
||
Bug 65827 comment 81 has a workaround for this bug: Append a query string to
the script URI. For example, http://example.com/download.cfm saves as
"export.csv.cfm", but http://example.com/download.cfm?test saves correctly as
"export.csv".
Comment 8•22 years ago
|
||
ok, the patch checked in for Bug 65827 should have fixed this; please reopen if not.
Status: UNCONFIRMED → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Updated•9 years ago
|
Product: Core → Core Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•