Déj*_*dić 43
如果你想创建tar.gz并且你使用的是PHP 5.3+,你可以使用PharData类:
try
{
$a = new PharData('archive.tar');
// ADD FILES TO archive.tar FILE
$a->addFile('data.xls');
$a->addFile('index.php');
// COMPRESS archive.tar FILE. COMPRESSED FILE WILL BE archive.tar.gz
$a->compress(Phar::GZ);
// NOTE THAT BOTH FILES WILL EXISTS. SO IF YOU WANT YOU CAN UNLINK archive.tar
unlink('archive.tar');
}
catch (Exception $e)
{
echo "Exception : " . $e;
}
Run Code Online (Sandbox Code Playgroud)
fox*_*oxy 22
您可以使用PHP的Zip类来创建zip文件,使用ZLib来创建gzip文件.
创建.zip文件:
$zip = new ZipArchive();
$res = $zip->open('test.zip', ZipArchive::CREATE);
$zip->addFromString('test.txt', 'file content goes here');
$zip->addFile('data.txt', 'entryname.txt');
$zip->close();
Run Code Online (Sandbox Code Playgroud)
创建.gz文件:
$file = "test.txt";
$gzfile = "test.gz";
$fp = gzopen($gzfile, 'w9'); // w == write, 9 == highest compression
gzwrite($fp, file_get_contents($file));
gzclose($fp);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37897 次 |
| 最近记录: |