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

查看:23
本文介绍了在没有 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.

推荐答案

At 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天全站免登陆