Hello,
I have written a script to download files, but once the dialog box to prompt the user for a filename pops up, it has a .html extension by default, regardless of what the original extension was. Although not a big deal, it is annoying and inconvenient, and I'd like to display the original filename by default. Any ideas?
The code I'm using is as follows. The user clicks on a download link that loads download.php.
Download.php:
-------------------------------------------------------------------------------------------
header('content-type=text/xml');
header('content-disposition: attachment;filename = Copyright.xml');
readfile('Copyright.xml');
--------------------------------------------------------------------------------------------
NOTE: There are no errors. The file is downloaded properly.
Thanks,
Jawad
Default filename in download dialog box
Moderator: General Moderators
Re: Default filename in download dialog box
Some browsers use the filename given - if it's formatted properly (I suspect the spaces are causing problems)
but some browsers don't use that, and prefer to use what's in the URL instead.
Also, the filename is only a suggestion. Browsers are free to use whatever name they want.
Code: Select all
header('content-disposition: attachment;filename=Copyright.xml');Also, the filename is only a suggestion. Browsers are free to use whatever name they want.
Re: Default filename in download dialog box
So... it doesn't really make sense to define a filename if the browser's not going to follow it...
I've noticed that, when the dialog box pops up, by default *.html files is selected (display only html files). This is probably what's causing the filename to have an html extension by default. The problem now is, even though i switch the file type selection to list all files, it always defaults to listing only html files. Maybe i'll have to play with the browser settings... btw, i'm using Opera, but the same thing happens with firefox.
Jawad.
I've noticed that, when the dialog box pops up, by default *.html files is selected (display only html files). This is probably what's causing the filename to have an html extension by default. The problem now is, even though i switch the file type selection to list all files, it always defaults to listing only html files. Maybe i'll have to play with the browser settings... btw, i'm using Opera, but the same thing happens with firefox.
Jawad.
Re: Default filename in download dialog box
I made the studpidest mistake
. There's supposed to be a colon in the headers ('content-type: text/xml) not ('content-type= text/xml');
Problem solved.
Jawad.
Problem solved.
Jawad.