-
Hi, for a variety of reasons, I am still (stuck) on version 2.4. I wanted to set a custom Cache-Control header, since there is no method for setting such a header. I looked at the Archive class (through which I can set options) and there is a method on it called I tried this: $zip_options = new ArchiveOptions(); // Imported as ArchiveOptions for legibility
...
...
...
$zip_options->setHttpHeaderCallback([$this, 'zipHeaders']); And my public function zipHeaders() {
return [
'header-one: header one value',
'another-header: value 2',
];
} I also implemented this function returning not an array but a In any event, neither of my attempts worked and none of my test headers were returned. I did trace it with x-debug and the callback was called (five times, which was interesting), but the headers were missing from the response. What kind of return value should be returned from the callable? Thank you. ps., If I am completely missing the boat and there is another way to set a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@apotek The header callback is used to actually set the header. Its arguments are the header name and the value. No return is expected. Therefore this is not the functionality you need. Instead, just disable the headers in ZipStream and set the headers yourself. See:
|
Beta Was this translation helpful? Give feedback.
-
Thank you for your reply. I am probably misunderstanding, but it seems that the instructions are then to: foreach ($headers as $header => $value) {
my_preferred_header_function_for_my_framework($header . ': ' . $value);
}
$zip->finish(); My experience with trying to send my own headers seemed to cause the zip to not download as a file (despite setting content disposition and filename and mimetype etc). I'll look at that again. So the instructions for 2.4 are:
Is that correct? Thanks again. |
Beta Was this translation helpful? Give feedback.
@apotek The header callback is used to actually set the header. Its arguments are the header name and the value. No return is expected.
Therefore this is not the functionality you need.
Instead, just disable the headers in ZipStream and set the headers yourself. See:
ZipStream-PHP/src/ZipStream.php
Lines 518 to 544 in 620c2aa