2013-05-08 3 views
0

ZipArchive 클래스를 사용하여 서버에있는 파일을 지우고 있습니다. 다운로드 한 ZIP을 WinRar로 추출 할 수는 있지만 WinZip으로 추출 할 수는 없습니다. 그리고 FileZilla를 통해 서버에서 직접 만든 ZIP 파일을 다운로드하면 Winzip으로 압축을 풀 수 있습니다.보관 파일로 PHP ZipArchive 클래스가 WinRar로 열리지 만 WinZip으로 열리지 않습니다.

은 내가 사용하고있는 다음 스크립트에서 참조하시기 바랍니다 : -

  $zip = new ZipArchive(); 
    //create the file and throw the error if unsuccessful 
    if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE)!==TRUE) { 
     exit("cannot open <$archive_file_name>\n"); 
    } 

    //add each files of $file_name array to archive 
    foreach($file_names as $files) { 

     $zip->addFile($file_path.$files,$files);  
    } 

    $zip->close(); 

    //get the size of the archive 
    $zipped_size = filesize($archive_file_name); 

    //set the required headers 
    header("Content-Description: File Transfer"); 
    //header("Content-type: application/zip"); 
    header("Content-type: application/octet-stream"); 
    header("Cache-Control: public", false); 
    header("Pragma: public"); 
    header("Expires: 0"); 
    //header("Content-type: application/x-zip-compressed"); 
    //header("Content-Type: application/force-download");// some browsers need this 
    header("Content-Disposition: attachment; filename=CV-archive.zip"); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
    header("Content-Transfer-Encoding: utf-8"); 
    header('Pragma: public'); 
    //header("Content-Length:". "$zipped_size"); 

    ob_clean(); //ob_clean and flush are required to make sure no extra line space is generated before output as it will corrupt the zip archive 
    flush(); 
    readfile("$archive_file_name"); 
    unlink("$archive_file_name"); // Now delete the temp file (some servers need this option) 
    foreach($file_names as $files) { 
     unlink($file_path.$files); 
} 
    exit; 

답변

2

당신의 다운로드 스크립트가 일부 포함에 ?> 태그 <?php 태그 앞에 아니면 이후에 추가 출력, 아마도 공백을 추가 파일. 또는 unlink($file_path.$files);에 경고가 표시되었을 수 있습니다.

+0

Hi Alvaro 님의 회신에 감사드립니다.하지만

+0

ZIP 파일 자체를 검사하지 않았다고 가정합니다. 제발. 파일 비교 도구를 사용할 수도 있습니다. –

+0

안녕하세요 Alvaro..i이 문제를 해결했습니다. 실제로 강제 다운로드로 인해 문제가 발생하여 브라우저에서 직접 다운로드 할 수있는 링크가 생겼습니다. 어쨌든 당신의 도움에 감사드립니다. 매우 감사. –

0

질문이 2 년이되었지만 다른 문제로 인해 동일한 동작을 발견했습니다. 내 보관소에있는 파일의 형식은 "\ 1-SOMFILENAME"이고 win rar가 파일을 추출 할 수는 있지만 Windows Archiver는 그렇지 않습니다.

첫 번째 문자가 이스케이프 된 다음 문자가 나오고 Windows 아카이버가이를 처리 할 수 ​​없습니다.