문제

PHP에서 zip 파일을 상자/추출하기위한 라이브러리가 있습니까?

ziparchive 클래스는 불규칙하게 작동하며 Php.net에 언급됩니다. (내가 확인한 모든 기능에 대해)

ziparchive :: addemptydir (버전 정보가없고 CVS에만있을 수 있음)

도움이 되었습니까?

해결책 4

알았어, 나는 확인했다 http://pear.php.net/package/archive_zip Irmantas에 의해 게시 된대로
그러나 이것은 이것을 말합니다 :
"이 패키지는 더 이상 유지 관리되지 않았으며 대체되었습니다. 패키지는 채널 Pecl.php.net, 패키지 Zip으로 이동했습니다." 그런 다음 Pear.php.net을 검색하고 우연히 발견했습니다.http://pear.php.net/package/file_archive

File_archive에는 매우 직관적 인 메소드 세트가 없습니다. 그러나 TAR 파일을 만들고 TAR 파일에서 파일을 추출하는 간단한 기능을 원했습니다.

스 니펫에 이어 : 타르 파일에서 파일 추출 ->

<?php
require_once "File/Archive.php";
$tmp = 'output';
$t1 = 'check.tar';
File_Archive::setOption('tmpDirectory','tmp');
$r = File_Archive::extract(
    File_Archive::read($t1.'/'),
    File_Archive::toFiles($tmp)
);
?>

타르 파일에 파일 추가 ->

<?php
require_once "Archive.php";
$dir = "../../mysql/data/blackStone/";
$files[0] = "";
$i = 0;
          if ($dh = opendir($dir)) {
              while (($file = readdir($dh)) !== false ) {
              if( $file != "." && $file != ".." )
                $files[$i++] = $dir.$file;
          }
      }

File_Archive::extract(
    $files,
    File_Archive::toArchive(
        'check.tar',
        File_Archive::toOutput()
    )
);

?>

다른 팁

Pear Archive_zip을 확인하십시오. 도움이 될 수 있습니다 http://pear.php.net/package/archive_zip/docs/latest/archive_zip/archive_zip.html

PHP는 GZIP를 통해 기본 ZIP 지원이 있습니다 (기본적으로 활성화되지 않을 수 있음) :
http://php.net/zlib

이 클래스를 사용할 수도 있습니다 (Drupal 은이 구현의 일부가 아닙니다).
http://drupal.org/node/83253

그만큼 ziparchive를 포함하는 동일한 모듈 또한 ZIP 파일에 절차 적으로 액세스 할 수있는 여러 기능이 포함되어 있습니다. 이 기능은 PHP 4 (4.0.7 이후) 및 PHP 5 (5.2.0 이후)에서 사용할 수 있습니다.

$zip = zip_open("foo.zip");
$files = [];

while ($entry = zip_read($zip)) {
    zip_entry_open($zip, $entry);
    $files[zip_entry_name($entry)] = zip_entry_read($entry, zip_entry_filesize($entry));
    zip_entry_close($entry);
}

zip_close($zip);

PHP에서 .NET 어셈블리로 호출 할 수 있습니다. 당신이 그것을 생각하지 않으면, 당신은 dotnetzip을 사용할 수 있습니다 - 그것은 신뢰할 수 있고 완전히 비어 일입니다.

CodePlex의 dotNetzip

샘플 코드 :

<?php
try
{
  $fname = "zip-generated-from-php-" . date('Y-m-d-His') . ".zip";
  $zipOutput = "c:\\temp\\" . $fname;
  # Use COM interop to get to Ionic Zip. (Windows only)
  $zip = new COM("Ionic.Zip.ZipFile");
  $zip->Name = $zipOutput;
  $dirToZip= "c:\\temp\\psh";
  # Encryption:  3=AES256, 2=AES128, 1=PKZIP, 0=None.
  $zip->Encryption = 3;
  $zip->Password = "AES-Encryption-Is-Secure";
  $zip->AddDirectory($dirToZip);
  $zip->Save();
  $zip->Dispose();

  if (file_exists($zipOutput))
  {
    header('Cache-Control: no-cache, must-revalidate');
    header('Content-Type: application/x-zip'); 
    header('Content-Disposition: attachment; filename=' . $fname);
    header('Content-Length: ' . filesize($zipOutput));
    readfile($zipOutput);
    unlink($zipOutput);
  }
  else 
  {
    echo '<html>';
    echo '  <head>';
    echo '  <title>Calling DotNetZip from PHP through COM</title>';
    echo '  <link rel="stylesheet" href="basic.css"/>';
    echo '  </head>';
    echo '<body>';
    echo '<h2>Whoops!</h2>' . "<br/>\n";
    echo '<p>The file was not successfully generated.</p>';
    echo '</body>';
    echo '</html>';
  } 
}
catch (Exception $e) 
{
    echo '<html>';
    echo '  <head>';
    echo '  <title>Calling DotNetZip from PHP through COM</title>';
    echo '  <link rel="stylesheet" href="basic.css"/>';
    echo '  </head>';
    echo '<body>';
    echo '<h2>Whoops!</h2>' . "<br/>\n";
    echo '<p>The file was not successfully generated.</p>';
    echo '<p>Caught exception: ',  $e->getMessage(), '</p>', "\n";
    echo '<pre>';
    echo $e->getTraceAsString(), "\n";
    echo '</pre>';
    echo '</body>';
    echo '</html>';
}

?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top