Rename file before download. Dont even know where to start

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bsprogs
Forum Newbie
Posts: 21
Joined: Mon Apr 23, 2007 1:07 am

Rename file before download. Dont even know where to start

Post by bsprogs »

I've made a private file upload site for myself and a few friends.

When a file is uploaded, I have the script change the file name to a random name. It then stores that name along with the user id and original file name in a database.

What I need to do now is when someone clicks to download the file I want it to show as as the original file name before they download it so they can save it as the original file name.

Example:

I upload "CarFun.mpeg".
After being uploaded, it's saved as "82bs88sns89ua.mpeg"

I click to download the file and I want it to say:
Save as: "CarFun.mpeg"

Any thoughts? I'm stumped.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

header() provides the ability to specify what filename the browser should "guess" to name it.

You're looking for the Content-Disposition header.
bsprogs
Forum Newbie
Posts: 21
Joined: Mon Apr 23, 2007 1:07 am

Post by bsprogs »

feyd wrote:header() provides the ability to specify what filename the browser should "guess" to name it.

You're looking for the Content-Disposition header.
Thank you so much! That just saved me a very long time.
Post Reply