루트 디렉토리의 모든 파일을 목록에 표시하는 프로젝트가 있습니다. 사용자는 파일 디렉토리를 탐색 할 수 있으며, 버튼을 사용하여 이름별로 파일을 검색 할 수 있습니다. downloadAll은 모든 파일을 다운로드 할 수 있습니다. downloadAll 버튼을 작동 시키려면 downloadAll.php 코드를 사용하십시오. 현재 디렉토리를 가져 와서 zip 파일을 만들고 자동으로 다운로드 할 수 있습니다. 그것은 창문에서 잘 작동합니다. 나는 리눅스에서 동일한 프로젝트를 실행하려고하지만,이 경우에는 빈 압축 파일을 다운로드한다. 또한이 파일을 열려고 시도하면 다음 메시지가 나타납니다.파일을 압축하여 자동으로 다운로드하는 PHP 코드입니다. 우분투가 아닌 우분투에서 작동합니다.
Archive: /tmp/archived_name.zip
[/tmp/archived_name.zip]
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
zipinfo: cannot find zipfile directory in one of /tmp/archived_name.zip or
/tmp/archived_name.zip.zip, and cannot find /tmp/archived_name.zip.ZIP, period.
나는 여러 시간 동안 무엇이 잘못 되었는 지 찾으려고 노력하고 있지만 찾을 수 없습니다. 누군가가 어떻게 든 나에게 도움을 줄 수 있거나 다른 코드를 사용할 수 있다면 정말 쓸만합니다.
downloadZip.php :
<?php
if ((isset($_GET['currentdirectory'])) && ($_GET['currentdirectory']!="")){
$the_folder = $_GET['currentdirectory'];
}
else {
$the_folder = "/var/www/my_project";
}
$the_folder1 = $the_folder;
$zip_file_name = 'archived_name.zip';
$download_file= true;
class FlxZipArchive extends ZipArchive {
public function addDir($location, $name) {
$this->addEmptyDir(str_replace("./","",$name));
$this->addDirDo($location, str_replace("./","",$name));
}
private function addDirDo($location, $name) {
$name .= '/';
$location .= '/';
$dir = opendir ($location);
while ($file = readdir($dir))
{
if ($file == '.' || $file == '..') continue;
$do = (filetype($location . $file) == 'dir') ? 'addDir' : 'addFile';
$this->$do($location . $file, str_replace("./","",$name) . $file);
}
}
}
$za = new FlxZipArchive;
$res = $za->open($zip_file_name, ZipArchive::CREATE);
if($res === TRUE)
{
$za->addDir($the_folder1, basename($the_folder1));
$za->close();
}
else { echo 'Could not create a zip archive';}
if ($download_file)
{
ob_get_clean();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=" . basename($zip_file_name) . ";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($zip_file_name));
readfile($zip_file_name);
}
unlink("archived_name.zip");
?>
"빈 zip 파일"은 아마 나보다 당신과 다른 것을 의미합니다. 0 바이트 에서처럼 파일이 실제로 비어 있습니까? 또는 우편 프로그램에서 파일을 볼 수 없습니까? 나는 아마 일부 PHP 오류가 zip 파일에 버려지고 있다고 가정합니다. 필자는 텍스트 편집기에서 zip 파일을 열어 PHP 오류를 찾으십시오. –
txt 편집기로 파일을 열었습니다. 비어 있습니다. –
그러면 다른 곳에서 발생하는 오류가있을 가능성이 큽니다. '$ download_file'을 false로 설정하고'error_reporting (E_ALL)'을 설정하여 오류가 있는지 확인하십시오. 그래도 문제가 해결되지 않으면 웹 서버 오류 로그를보십시오. 아파치의 경우 기본값은'/ var/log/apache2/access.log' 또는 유사합니다. –