HTTP Headers Help

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Digital Wokan
Date:  
Subject: HTTP Headers Help
Bryce C wrote:
> Ok, not exactly on-topic but it does relate.
> I'm trying to write a php script that passes a binary file through it
> for download. This is to protect the file's true location (not web
> accessible) and to allow my logger to log the transaction.
> Unfortunately, the filename doesn't get copied. That is, the file to
> download shout be x.tar.gz but I get download.php. Can someone help?
> Note: I can't configure any of the services.
> Note2: I know it's possible because I've seen other sites do it.
>
> Thanks,


<?php
/* filename set at some earlier point by mechanism of your choice */
header("Content-type: application/unknown");
header("Content-Disposition: inline; filename=".$filename);
/* Now open the real file you want and write it out in raw (binary) form
as if you were echoing or printing an html page. */
?>

The content type application/unknown forces a download instead of the
browser attempting to render it (as would be done with jpegs, text,
html, etc). It's also possible to use application/octet-stream, but
that's not dependable when the content is a jpeg or gif. Once you've
started with those lines, you can read in whatever file you're
downloading and write it out as if it were going to the screen. I use
this all the time at work for creating downloadable tab separated value
dumps of SQL queries.