采用的扩展是php_rar.dll。php版本是5.5。
$rar_file = rar_open($fileName); //此处返回false
调用异常查看后
RarException :: setUsingExceptions ( true );
得到的异常信息为:
unRAR internal error: Failed to open  D:\Desktop.rar : ERAR_BAD_ARCHIVE
网上搜了一下,ERAR_BAD_ARCHIVE表示不是有效的rar文件,可是我这个压缩文件确实使用WinRAR压缩的,也可以正常解压的。求助各位大神帮忙分析一下吧

解决方案 »

  1.   

    $file = fopen($fileName,'rb');
                $bin = fread($file,2);
                $strinfo = @unpack('C2chars', $bin);
                $typecode = intval($strinfo['chars1'].$strinfo['chars2']);            switch ($typecode) {
    case 7790: $fileType = 'exe'; break;
    case 7784: $fileType = 'midi'; break;
    case 8297: $fileType = 'rar'; break;
    case 255216: $fileType = 'jpg'; break;
    case 7173: $fileType = 'gif'; break;
    case 6677: $fileType = 'bmp'; break;
    case 13780: $fileType = 'png'; break;
    default: echo'unknown';
                 } 
                 echo $fileType; echo $typecode;exit;
    用以上方法测试了一下,文件类型确实是rar的。
    崩溃了
      

  2.   

    我用winrar压缩的,可以正常解压。
    我在一楼回复的不就读取了文件头么,还要读哪些信息才能判断文件头不对。
      

  3.   

    你得用pecl rar 压缩,而且版本要大于等于2.0.0。
      

  4.   

    就是在pecl 官网上下载的
      

  5.   

    https://stackoverflow.com/questions/14555730/how-to-extract-rar-archive-files-and-folders-using-php-in-windows我也只能帮到这了