F
F
fiter2017-03-05 02:11:40
Laravel
fiter, 2017-03-05 02:11:40

How to create password protected zip in laravel 5?

Hello!
What is the easiest way in Laravel 5.4 to create a password-protected zip archive with a text file, and immediately spit it out to the user without saving it on the server?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Ne-Lexa, 2017-03-05
@fiter

If without saving to disk:

$password = 'ChangeMe';
$zipFile = \PhpZip\ZipOutputFile::create();
$zipFile->addFromString('filename.txt', 'Data content');

// установите пароль для нужного алгоритма шифрования
$zipFile->setPassword($password); // для WinZip AES шифрования
// или
$zipFile->setPassword($password, \PhpZip\Model\ZipEntry::ENCRYPTION_METHOD_TRADITIONAL); // для традиционного шифрования

$zipFile->outputAsAttachment('archive.zip');

Documentation

A
Anton, 2017-03-05
Reytarovsky @Antonchik

php.net/manual/ru/zip.examples.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question