zanysoft / laravel-zip

MIT License
300 stars 95 forks source link

Set Password not working #13

Closed webexpert4rv closed 3 years ago

webexpert4rv commented 5 years ago

I am trying to create a password protected zip file, eerything works fine except password. My code is as follows: $zip = \ZanySoft\Zip\Zip::create(storage_path().'/app/uploads/bdo/file.zip');

$zip->add(storage_path().'/app/uploads/bdo/abc.txt');
$password = 'top-secret';

if (!$zip->setPassword($password)) {
    throw new RuntimeException('Set password failed');
}

$zip->close();

Please help.

praveenpatel95 commented 5 years ago

Hello i am also facing same problem, and they still no give any reply

Pie-Jie commented 5 years ago

Hi, is there a fix for this issue?

praveenpatel95 commented 5 years ago

Yes i fixed this issue.

$zip = new ZipArchive(); $zip->open($savepath, ZipArchive::CREATE | ZipArchive::OVERWRITE); $alluser=MyResume::all(); $zip->setPassword('123456'); foreach ($alluser as $row) { $filename=basename($row->resume); $zip->addFile($row->resume, $filename); $zip->setEncryptionName($filename, ZipArchive::EM_AES_256); } $zip->close(); return response()->download($savepath);