Page 1 of 1

How to trim file location for download script?

Posted: Sun Oct 16, 2005 10:39 pm
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

Posted: Sun Oct 16, 2005 10:42 pm
by feyd
the trim functions are not helpful for this.. basename()

Posted: Sun Oct 16, 2005 10:45 pm
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.