Amol Maske
Amol Maske

Reputation: 1

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.

Upvotes: 0

Views: 5806

Answers (2)

Timothée Groleau
Timothée Groleau

Reputation: 1950

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

Upvotes: 0

Ravinder Singh
Ravinder Singh

Reputation: 3133

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.

Upvotes: 1

Related Questions