在没有exec/passthru的情况下从PHP目录构建Tar文件 [英] Build Tar file from directory in PHP without exec/passthru

查看:87
本文介绍了在没有exec/passthru的情况下从PHP目录构建Tar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个当前主机的客户端不允许我通过exec()/passthru()/ect使用tar,并且我需要定期并以编程方式备份​​该站点,所以有解决方案吗?

So I have a client who's current host does not allow me to use tar via exec()/passthru()/ect and I need to backup the site periodicly and programmaticly so is there a solution?

这是Linux服务器.

This is a linux server.

推荐答案

http://pear.php .net/package/Archive_Tar ,您可以卸载PEAR tar软件包并使用它来创建归档文件:

At http://pear.php.net/package/Archive_Tar you can donload the PEAR tar package and use it like this to create the archive:

<?php
require 'Archive/Tar.php';
$obj = new Archive_Tar('archive.tar');
$path = '/path/to/folder/';
$handle=opendir($path); 
$files = array();
while(false!==($file = readdir($handle)))
 {
    $files[] = $path . $file;
 }

if ($obj->create($files))
 {
    //Sucess
 }
else
 {
    //Fail
 }
?>

这篇关于在没有exec/passthru的情况下从PHP目录构建Tar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆