I just need to check uploaded zip or rar file is password protected or not.
Through php how can we check this?
I only need message that file is password protected when upload.
Thanks,
hello , thanks for your replay and help. but every time $var_val[0] have 0(No Password) value if password protected or not. Thanks.
Of course your server needs 7z and unrar installed. But I assume you do since you are dealing with these types. Since the actual shell commands depend on your server OS you may need to edit.
here is 7zip:
$zipfile = './uploaded.zip';
$zip_cmd = '7za l -slt -- '.$zipfile.' | grep -i -c "Encrypted = +"';
exec($zip_cmd, $zip_val);
if($zip_val[0] == 1) {
echo "Password protected\n";
} else {
echo "No password\n";
}
Here is unrar:
$rarfile = './uploaded.rar';
$rar_cmd = 'unrar x -p- -y -o+ '.$rarfile.' 2> /dev/null | grep -i -c "$Total errors: .*$"';
exec($rar_cmd, $rar_val);
if($rar_val[0] == 1) {
echo "Password protected\n";
} else {
echo "No password\n";
}
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.