用ZipArchive创建zip,解压时提示文件损坏
用addFromString添加,文件是都添加进去了,也有大小显示,但解压就说文件损坏

解决方案 »

  1.   


    $urlcoup = $_POST['urlcoup'];    $imagesURLArray = explode(";",$urlcoup);        $zip = new ZipArchive();
            $filename = "pinzip/".time().rand(101,999).".zip";        if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
                
                exit("cannot open <$filename>\n");
            }
            foreach($imagesURLArray as $imagesURL)
            {
                $zip->addFromString(basename($imagesURL), file_get_contents($url.$imagesURL));
              
            }
            $zip->close();
           
            header('Content-type: application/zip');
            header('Content-Disposition: attachment; filename="'.time().rand(101,999).'.zip"');
            
            readfile($filename);
    我觉得代码上没有错,因为在本机上操作可以正常解压,放到服务器上就出问题,但服务器上的php.ini里我我添加了 extension=php_zip.dll 本来没有的
      

  2.   

    php5.3是自带zip功能,不能添加
    php5.2要添加
      

  3.   

    进过检查,问题应该出在 file_get_contents这个函数上啊,没有这个函数,直接给字符串输入txt文件,出来的ZIP都可以正常解压,但用这个函数将文件读取成字符串在写入就会出现文件损坏............何解