Change displayed file name to download

--0-805244496-1268598598=:29662
Content-Type: text/plain; charset=us-ascii

Hi,

I'm using the following code:
____________________
$fp = fopen($filename, 'r+');
$content = fread($fp,
filesize($filename));
fclose($fp);
header("Content-type:
application/msword");
header("Content-Disposition: attachment;
filename=$filename");
echo $content;
exit;
___________________

Now when downloading a file the default name that appears for the user is
the realname of the file i the server with the real path the only
difference is that the slashes are modified by underscore.

My
question is: is there any way how to control the name that will be
displayed for the customer? Or at least skip the path and display just
the file's name?

Thank you


____________________________________________________________ ______
Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail. Click on Options in Mail and switch to New Mail today or register for free at http://mail.yahoo.ca
--0-805244496-1268598598=:29662--
PHP Developer [ So, 14 März 2010 21:29 ] [ ID #2035035 ]

Re: Change displayed file name to download

Hi

Make a $new_filename and put that in the header:

$neW_filename = "downloadfile." . $filetype;
header("Content-Disposition: attachment; filename=$new_filename");
(the content of the file is now in $content, so if you like you could
also change the value of $filename if you preferrer that)

You'll need to detect $filetype from $filename to always have the same
filename as the original file.

/kim

Php Developer wrote on 14/03/2010 21:29:
> Hi,
>
> I'm using the following code:
> ____________________
> $fp = fopen($filename, 'r+');
> $content = fread($fp,
> filesize($filename));
> fclose($fp);
> header("Content-type:
> application/msword");
> header("Content-Disposition: attachment;
> filename=$filename");
> echo $content;
> exit;
> ___________________
>
> Now when downloading a file the default name that appears for the user is
> the realname of the file i the server with the real path the only
> difference is that the slashes are modified by underscore.
>
> My
> question is: is there any way how to control the name that will be
> displayed for the customer? Or at least skip the path and display just
> the file's name?
>
> Thank you
>
>
> ____________________________________________________________ ______
> Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail. Click on Options in Mail and switch to New Mail today or register for free at http://mail.yahoo.ca


--
Kind regards
Kim Emax - masterminds.dk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Kim Madsen [ So, 14 März 2010 21:42 ] [ ID #2035037 ]

Re: Change displayed file name to download

You can set the name to display as you see fit, just change $filename
to your liking right before the header() call. If you just want to cut
the path, use basename($filename)

Regards
Peter

On 14 March 2010 21:29, Php Developer <pdeveloper [at] rocketmail.com> wrote:
> Hi,
>
> I'm using the following code:
> ____________________
> $fp =C2=A0 =C2=A0 =C2=A0=3D fopen($filename, 'r+');
> $content =3D fread($fp,
> filesize($filename));
> fclose($fp);
> header("Content-type:
> application/msword");
> header("Content-Disposition: attachment;
> filename=3D$filename");
> echo $content;
> exit;
> ___________________
>
> Now when downloading a file the default name that appears for the user is
> the realname of the file i the server with the real path the only
> difference is that the slashes are modified by underscore.
>
> My
> question is: is there any way how to control the name that will be
> displayed for the customer? Or at least skip the path and display just
> the file's name?
>
> Thank you
>
>
> =C2=A0 =C2=A0 =C2=A0_____________________________________________________=
_____________
> Be smarter than spam. See how smart SpamGuard is at giving junk email the=
boot with the All-new Yahoo! Mail. =C2=A0Click on Options in Mail and swit=
ch to New Mail today or register for free at http://mail.yahoo.ca



--
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
</hype>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Peter Lind [ So, 14 März 2010 21:43 ] [ ID #2035038 ]
PHP » gmane.comp.php.general » Change displayed file name to download

Vorheriges Thema: SimpleXML: convert xml to text
Nächstes Thema: php - page flow issue...