drtohng5613 2014-01-30 04:01
浏览 84

Php through如何检查上传的zip或rar文件是否受密码保护

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.

  • 写回答

1条回答 默认 最新

  • doutun1875 2014-01-30 04:48
    关注

    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
    ";
    } else {
            echo "No password
    ";
    }
    

    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
    ";
    } else {
            echo "No password
    ";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?