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