Downloading files, without internet renumbering... [message #169359] |
Wed, 08 September 2010 14:37 |
jodleren
Messages: 7 Registered: September 2010
Karma: 0
|
Junior Member |
|
|
Hi all
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);
?>
|
|
|
Re: Downloading files, without internet renumbering... [message #169361 is a reply to message #169359] |
Wed, 08 September 2010 15:35 |
Erwin Moller
Messages: 228 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 9/8/2010 4:37 PM, jodleren wrote:
> Hi all
>
> 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
>
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
|
|
|
|
Re: Downloading files, without internet renumbering... [message #169392 is a reply to message #169390] |
Thu, 09 September 2010 08:49 |
jodleren
Messages: 7 Registered: September 2010
Karma: 0
|
Junior Member |
|
|
On Sep 9, 10:26 am, "Álvaro G. Vicario"
<alvaro.NOSPAMTH...@demogracia.com.invalid> wrote:
> El 08/09/2010 16:37, jodleren escribió/wrote:
>
>> 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?
>
> 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:
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...
|
|
|