简体   繁体   中英

Create password protected ZIP file in PHP

Hi i am Using Following Code For create password protected zip file

$password = 'pass';
$outfile = 'download.zip';    
$infile = 'xml.php';    
header("Content-type: application/octet-stream");   
header("Content-disposition: attachment; filename=$outfile");    
@system("zip -P $password $outfile $infile");    
readfile($outfile);    
@unlink($outfile);

but it is not working.

Same code is working for me. When i first ran this, i got permission error, when i gave the permission to folder, it worked. You can also check for folder permissions. It might also work for you.

Assuming your example is dumbed down and the password comes from somewhere else (maybe user input?), the system call is not safe! If it contains characters that have meaning to the shell, you'll get undesired result. Make sure you escape parameters with escapeshellarg: http://php.net/manual/en/function.escapeshellarg.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM