Is there a way to give a file a header without putting php in it?
At the moment I’m using file_put_contents() to create a text file. Can I, when I create it, or after I’ve created it, give it a header somehow?
Obviously there’s header() but that gives a header to the file that it’s in, not another one.
I could wrap the file in question in php in order to be able to use header() from within it, but just wondering if there’s a way to do it externally, to a file?
The header() function sends the header to the browser as a pre-amble to sending output, it’s not actually putting it in a file as such. Can you elaborate on exactly what you’re trying to achieve? You’ve created a text file, but what kind of header do you want to give it when the user accesses the file? Normally this is decided when the http server delivers the file, the default header seems to be decided by the filename extension. Specifically which header do you want to add?
Thanks for the reply.
The header I want to add is:
It’s a .tcx file, which is basically an xml file. I want the browser to download it not display it.
Looks like it’s an Apache thing then? Something to add to the .htaccess file maybe?
I would say so, yes. The only other way is how you mentioned originally - instead of linking to the file, link to a php file that sends the correct header then outputs the file contents.
Header set Content-Type: application/octet-stream
in .htaccess file did it. Thanks.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.