Jump to content

PHP returns file as request, how to set name?


cpuworks

Recommended Posts

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....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.