cpuworks Posted July 19, 2010 Share Posted July 19, 2010 With code similar to this: <?php header('Content-Type: application/msword'); header('Content-Disposition: attachment; filename=filename.doc'); readfile('/not/in/web/root/word.doc'); ?> the user gets a desired doc, after I verify they can have it. In other words, they call my program, access.php, with something like "access.php?FN=word.doc", it checks their id info, then if OK it echoes the file back. All well and good, except that the file is returned (obviously) as "access.php". I don't want to write the file to a temporary location and give them a link to it, because then I'd have to make sure it gets deleted quickly - I want to control access to the files, so writing them to a known location and leaving them there is no good. Is there a way to change the filename the requester gets? Like force it do be "word.doc", as in this example? Best would be to trigger their download prompt, so they get to choose where to save it. etc. Can I stream it back as a ZIP? Would that be a decent approach? But that still doesn't help the file name problem... I think I'm missing something obvious.... Quote Link to comment https://forums.phpfreaks.com/topic/208212-php-returns-file-as-request-how-to-set-name/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 19, 2010 Share Posted July 19, 2010 To start with, the file name must be enclosed in double-quotes - header('Content-Disposition: attachment; filename="filename.doc"'); Quote Link to comment https://forums.phpfreaks.com/topic/208212-php-returns-file-as-request-how-to-set-name/#findComment-1088303 Share on other sites More sharing options...
cpuworks Posted July 20, 2010 Author Share Posted July 20, 2010 Thanks, that was it all along, the double-quotes... sigh... Quote Link to comment https://forums.phpfreaks.com/topic/208212-php-returns-file-as-request-how-to-set-name/#findComment-1088700 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.