How to trim file location for download script?

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
plastica
Forum Newbie
Posts: 2
Joined: Sun Oct 16, 2005 10:33 pm

How to trim file location for download script?

Post by plastica »

I'm hacking a download management system for my site, and and working on the section to obfuscate the original file location and send a chosen file directly to a user's browser. (the files are not actually in a web viewable directory though). I have the script working so when a user calls a link, the script outputs directly to the browser. However, at the moment I store the full file location in $file (ie mysql query might end up resulting in.. $file = /home/username/downloads/test.mp3) however I still have an issue i want to resolve....

header("Content-Disposition: attachment; filename=\"$file\"");

as the filename will still *look like* the files location, when is just poor practice regardless of implications. So I've looked into using trim() and ltrim() to trim all characters before the last "/" from the string, and store that in $filename to output in the headers. No such luck so far.

Anyone have any idea if/how can i do this? Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the trim functions are not helpful for this.. basename()
plastica
Forum Newbie
Posts: 2
Joined: Sun Oct 16, 2005 10:33 pm

Post by plastica »

that was amazing response time, i just tried basename() it and it works perfectly.... now i just need to do a system to do mime types from extensions, as my host provider's php doesnt support the mime type function.
Post Reply