FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Downloading files, without internet renumbering...
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Downloading files, without internet renumbering... [message #169359] Wed, 08 September 2010 14:37 Go to next message
jodleren is currently offline  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 Go to previous messageGo to next message
Erwin Moller is currently offline  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 #169390 is a reply to message #169359] Thu, 09 September 2010 07:26 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
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
--
Re: Downloading files, without internet renumbering... [message #169392 is a reply to message #169390] Thu, 09 September 2010 08:49 Go to previous message
jodleren is currently offline  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...
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Php Switch Case
Next Topic: Re: Php code for ajax encoding
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 03:05:43 GMT 2024

Total time taken to generate the page: 0.01987 seconds