I have this simple script to download file frome anywhere. It gets a
parameter and passes the file on.
The problem is that files like ABC01234.nc works well.
Then someone adds a version to is to it becomes ABC01234.2.nc - the .2
got added causing my browser (?) to change it ABC01234[1].2.nc - the
[1] bothers me.
CanI get rid of that?
WBR
Sonnich
Code:
<?php
function ExtractFilename($filename)
{
if(strrpos($filename, '\\')===false)
return $filename;
else
return substr($filename, strrpos($filename, '\\')+1);
}
$file=$_GET['file'];
$filename=ExtractFileName($file);
header('Content-type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"$filename\"");
readfile($file);
?>
Hi Sonnich,
That had nothing to do with PHP.
I expect it is your browser that numbers the files.
Firefox, for example, will happily save files in the same directory (the
one you appointed as download directory), and will start numbering them
if you download a file with the same name in that directory.
So there is nothing wrong with the following header:
header("Content-Disposition: attachment; filename=\"$filename\"");
Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
It's close to impossible to instruct Internet Explorer to download a
file with a specific name. Seriously. The best thing you can do is to lie:
1. Enable the URL rewriting module of your web server
2. Configure a redirection from
http://example.com/download/ABC01234.2.nc
to
http://example.com/download.php?filename=ABC01234.2.nc
You can still get a mangled name but there's not much else you can do.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
I figured that yesterday, I tried file:// and got the same result. So
I will just have to let it be as it was.
The funny thing is that a file in a subfolder of the system will work
well.
Just wonder maybe I got it now...