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;
Hi Alvaro 님의 회신에 감사드립니다.하지만 php 앞에 공백이 없는지 확인하고 ob_clean() 및 flush()를 사용하여 실제 출력 전에 줄 간격이나 공백이 없는지 확인했습니다. –
ZIP 파일 자체를 검사하지 않았다고 가정합니다. 제발. 파일 비교 도구를 사용할 수도 있습니다. –
안녕하세요 Alvaro..i이 문제를 해결했습니다. 실제로 강제 다운로드로 인해 문제가 발생하여 브라우저에서 직접 다운로드 할 수있는 링크가 생겼습니다. 어쨌든 당신의 도움에 감사드립니다. 매우 감사. –