题
有没有装箱库/ PHP中提取zip文件?
在ZipArchive类的工作不稳定,而这是在php.net提到: (为我检查每个功能)
ZipArchive :: addEmptyDir (无可用的版本信息,可能只有在CVS)
解决方案 4
好的,我检查 http://pear.php.net/package/Archive_Zip 如张贴Irmantas,点击 但它说的:点击 “该软件包不再被维护和已被取代。软件包已经移动到信道pecl.php.net,包拉链”。 然后我搜索pear.php.net和偶然发现: http://pear.php.net/package/File_Archive
File_Archive不具有一个非常直观的一套方法虽然。 但是,我想制作一个tar文件的简单的功能,并 从一个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)
);
?>
将文件添加到tar文件 - >
<?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天然邮编支持(可能不是默认启用):结果 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 - 它是可靠的,完全非不稳定
样品的编号:
<?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>';
}
?>