Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Downloading files, without internet renumbering...

2 views
Skip to first unread message

jodleren

unread,
Sep 8, 2010, 10:37:08 AM9/8/10
to
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);
?>

Erwin Moller

unread,
Sep 8, 2010, 11:35:24 AM9/8/10
to
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

"Álvaro G. Vicario"

unread,
Sep 9, 2010, 3:26:35 AM9/9/10
to
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:

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
--

jodleren

unread,
Sep 9, 2010, 4:49:44 AM9/9/10
to
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...

0 new messages