修改配置文件:
vim /usr/local/php/etc/php.ini
[Phar]
phar.readonly = Off
壓縮:
a. 創(chuàng)建壓縮腳本:
vim compress.php
?php
$exts = array(
'*',
);
$dir = __DIR__;
$file = 'test.phar';
$phar = new Phar(__DIR__ . '/' . $file, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, $file);
$phar->startBuffering();
foreach ($exts as $ext) {
$phar->buildFromDirectory($dir, '/\.' . $ext . '$/');
}
$phar->delete('build.php');
$phar->setStub($phar->createDefaultStub('index.php'));
$phar->stopBuffering();
echo "打包完成".PHP_EOL;
b. 執(zhí)行壓縮腳本:
php /home/lee/php/compress.php
c. 查看壓縮包:
解壓:
a. 創(chuàng)建解壓腳本:
vim /home/lee/php/depress.php
?php
define('ROOT',__DIR__);
$dir = ROOT.'/extract';
if(!is_dir($dir)){
@mkdir($dir);
}
$phar = new Phar(ROOT.'/test.phar');
$phar->extractTo($dir,null,true);
echo "解壓完成".PHP_EOL;
b. 執(zhí)行解壓腳本:
php /home/lee/php/depress.php
c. 查看解壓文件:
您可能感興趣的文章:- 攻擊者是如何將PHP Phar包偽裝成圖像以繞過(guò)文件類(lèi)型檢測(cè)的(推薦)
- PHP開(kāi)發(fā)之歸檔格式phar文件概念與用法詳解【創(chuàng)建,使用,解包還原提取】
- PHP中phar包的使用教程
- 解決PHP 7編譯安裝錯(cuò)誤:cannot stat ‘phar.phar’: No such file or directory