Computer >> 컴퓨터 >  >> 프로그램 작성 >> PHP

PHP에서 디렉토리를 압축하는 방법은 무엇입니까?


PHP에서 폴더를 압축 및 압축 해제하기 위해 PHP ZipArchive 클래스를 사용할 수 있습니다. PHP 5.3부터 이 클래스가 내장되어 있습니다. Windows에서 사용하려면 php.ini 내에서 php_zip.dll을 활성화해야 합니다.

예시

<?php
//Enter the name of directory
   $pathdir = "Directory Name/";
//Enter the name to creating zipped directory
   $zipcreated = "test.zip";
//Create new zip class
   $newzip = new ZipArchive;
   if($newzip -> open($zipcreated, ZipArchive::CREATE ) === TRUE) {
      $dir = opendir($pathdir);
      while($file = readdir($dir)) {
         if(is_file($pathdir.$file)) {
            $newzip -> addFile($pathdir.$file, $file);
         }
      }
      $newzip ->close();
   }
?>