2017-06-05 11:22
浏览 52


I am trying to extract the contents of a folder within a tarball using PHP. I am using the following PHP to download and extract the archive:


function wget($address,$filename) {

$newdir = 'test';

echo '<br>Downloading latest gzipped WordPress tarball';

wget('http://wordpress.org/latest.tar.gz', 'latest.tar.gz');

echo '<br>about to Extract from gz';

// decompress from gz
$p = new PharData('latest.tar.gz');
$p->decompress(); // creates files.tar

echo '<br>Extracted from gz';

// unarchive from the tar
$phar = new PharData('latest.tar');
echo '<br>Un-TARd';

echo '<br>Complete';


My problem is that this script extracts the tarball into /test/wordpress whereas I need it to extract to /test/. I have read through this documentation on the PHP.net Manual and replaced part of my code to meet one of the examples there. The code I had was:


And I changed that to:

$phar->extractTo($newdir, 'wordpress');

But that didn't work. The PHP script processed through to the end but the /test/ directory was empty. The aim of this is to create a one-click WordPress install on our local dev server.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试使用PHP提取tarball中文件夹的内容。 我使用以下PHP下载并解压缩存档:

function wget($ address,$ filename){
 file_put_contents($ filename  ,file_get_contents($ address)); 
 $ newdir ='test'; 
echo'&lt; br&gt;下载最新的gzip压缩WordPress tarball'; 
wget('http:// wordpress。  org / latest.tar.gz','latest.tar.gz'); 
echo'&lt; br&gt;即将从gz中提取'; 
 $ p = new PharData  ( 'latest.tar.gz'); 
 $的对 - &GT;解压缩();  //创建files.tar 
echo'&lt; br&gt;从gz'中提取; 
 $ phar = un Phaf = new PharData('latest.tar'); 
echo'&lt;  BR&GT;取消TARD'; 
 $的的药&GT; extractTo($ NEWDIR);  
echo'&lt; br&gt;完成'; 

我的问题是这个脚本将tarball提取到 / test / wordpress 而我需要它提取到 / test / 。 我在PHP.net手册上阅读了这个文档并替换了部分 我的代码满足其中一个例子。 我的代码是:

$ phar-&gt; extractTo($ newdir);

我改变了 to:

$ phar-&gt; extractTo($ newdir,'wordpress');

但是没有' 工作。 PHP脚本一直处理完毕,但 / test / 目录为空。 目的是在我们的本地开发服务器上创建一键式WordPress安装。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题