0
zip 아카이브 내의 디렉토리 내용을 출력 디렉토리로 추출해야합니다.PHP Zip : 디렉토리의 내용을 추출하십시오.
zip 내의 디렉토리 이름은 무엇이든 될 수 있습니다. 그러나 zip 아카이브의 기본 디렉토리는이 디렉토리뿐입니다. 디렉토리에 zip 아카이브에있는 파일이 몇 개라도있을 수 있습니다.
- d0001
- My Folder
- view.php
- tasks.txt
- file1.txt
- picture1.png
- document.doc
출력 디렉토리의 내용은 다음과 같이해야합니다 :
이- My Folder
- view.php
- tasks.txt
- file1.txt
- picture1.png
- document.doc
내가 현재 가지고있는 코드는 내용을 삭제
함께 할 것입니다 내부 지퍼 파일 구조는 라인 논제 출력 디렉토리의 전체 zip 아카이브를 디렉토리로 추출합니다.
function Unzip($source, $destination) {
$zip = new ZipArchive;
$res = $zip->open($source);
if($res === TRUE) {
$zip->extractTo($destination);
$zip->close();
return true;
} else {
return false;
}
}
function rrmdir($dir, $removebase = true) {
if(is_dir($dir)) {
$objects = scandir($dir);
foreach($objects as $object) {
if($object != "." && $object != "..") {
if(filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
if($removebase == true)
rmdir($dir);
}
}
$filename = '/home/files.zip';
$dest = '/home/myfiles/';
if(is_dir($dest)) {
rrmdir($dest, false);
$unzip = Unzip($filename, $dest);
if($unzip === true) {
echo 'Success';
} else
echo 'Extraction of zip failed.';
} else
echo 'The output directory does not exist!';
모든 함수 rrmdir()
은 출력 디렉토리의 내용을 제거합니다.