<?php
$password = 'pass';
$outfile = 'download.zip';
$infile = 'file.txt';
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=$outfile");
@system("zip -P $password $outfile $infile");
readfile($outfile);
@unlink($outfile);
The answer from @Paras is good. But there is one thing that can confuse newcommers:
'options' => [
'Expires' => gmdate('D, d M Y H:i:s GMT', strtotime('+1 month')),
>>> WRONG visibility' => 'public', WRONG <<<
]
If you want to define global options for the HEADERS, the options array is the right way to go. But if you also want to define the visibility, you can not mix it up. Visibility has to be define outside of options array.
👍
'visibility' => 'public',
'options' => ['Expires' => gmdate('D, d M Y H:i:s GMT', strtotime('+1 month'))]
@sources: