Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

rename file on download

2:30 pm on May 26, 2009 (gmt 0)

New User

10+ Year Member

joined:Feb 21, 2008
posts: 9
votes: 0

Then I upload the file, for example "MG_CV.doc" the php code renames the file to "38912831_7183791.doc" and then uploads it. In database are saved the old and new names of the files (MG_CV.doc, 38912831_7183791.doc).

After I call
<a href='MG_CV.doc'>download file</a>
I need on clicking on "download file" download 38912831_7183791.doc but in "save as dialog" must be "MG_CV.doc" how can I do this in PHP.

4:51 pm on May 26, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
votes: 0

1. store the real file name and the original file name in a database.

2. Don't directly link to the file, link to a script that opens the DB, gets the real file name and the original file name.

3. Use one of the open methods to open the file and print to the browser. This will allow you to secure the files too, if needed.

4. When outputting the download dialog, populate the "filename" attribute in the header.

One example here [webmasterworld.com] from a recent thread