|
Ever wondered how to set the name of a download file? There are two
ways to do this. One way is to pass the name of the file in the header.
Here is some sample code:
header( "Content-type: application/x-something" );
header( "Content-Disposition: attachment; filename=test.txt" );
header( "Content-Description: PHP3 Generated Data" );
If you want the file to be saved, the content type needs
to be something that the browser does not recognize.
You can also send a known 'Content-type' and have the
browser do the right thing.
Click here to see this in action.
Click here to see the source.
Another method is to send a "location" header with the url of the
desired file.
Some more notes:
-
The other thing that I found out about IE 5.5 is that going directly
to the file i.e. http://host/setfile.php works but
going to http://host/ and then clicking on
the "setfile.php" file gives weird results. In the second case you have to
select "Open" (NOT Save) and then another dialog will appear where
you can click "Save" and then the file name will be correct.
-
This does not seem to work with Konqueror.
|