Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save josephdicdican/abbbae881963d3161b4e566d8b13b84c to your computer and use it in GitHub Desktop.
Save josephdicdican/abbbae881963d3161b4e566d8b13b84c to your computer and use it in GitHub Desktop.
Generating Password Protected ZIP Files using PHP

Alternative way of creating Password protected zip file when you are not ready to upgrade to php 7

<?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);

S3 Setting Expiration when uploading file

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:

  1. https://thomashunter.name/posts/2008-09-20-generating-password-protected-zip-files-using-php
  2. https://stackoverflow.com/a/48375565
  3. https://laracasts.com/discuss/channels/laravel/how-to-zip-and-upload-files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment