建立从目录TAR文件在PHP没有EXEC /中继
题
所以我有一位客户,谁是当前主机不允许我使用EXEC通过))焦油(/中继(/ ECT,我需要备份网站定期对与programmaticly那么有没有解决的办法?
这是一个Linux服务器。
解决方案 2
目前 http://pear.php.net/package/Archive_Tar 可以donload的PEAR焦油包和使用它像这样创建存档:
<?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
}
?>
其他提示
PHP 5.3提供了解决这个问题的一个更简单的方法。
看这里: http://www.php.net/manual/en /phardata.buildfromdirectory.php
<?php
$phar = new PharData('project.tar');
// add all files in the project
$phar->buildFromDirectory(dirname(__FILE__) . '/project');
?>
有是的Archive_Tar 库。如果不能被用于某种原因,拉链扩展程序可能是另一种选择。
我需要一个解决方案,将在Azure网站(IIS)工作,并遇到了麻烦,使用来自其他答案方法在服务器上创建新文件。为我工作的解决方案是使用小 TbsZip 库压缩,不需要写文件中的任何地方服务器 - 它只是通过HTTP直接返回
这线程是老了,但这种方法可能会有点更通用的和完整的答案,所以我张贴代码作为替代:
// Compress all files in current directory and return via HTTP as a ZIP file
// by buli, 2013 (http://buli.waw.pl)
// requires TbsZip library from http://www.tinybutstrong.com
include_once('tbszip.php'); // load the TbsZip library
$zip = new clsTbsZip(); // instantiate the class
$zip->CreateNew(); // create a virtual new zip archive
// iterate through files, skipping directories
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.'));
foreach($objects as $name => $object)
{
$n = str_replace("/", "\\", substr($name, 2)); // path format
$zip->FileAdd($n, $n, TBSZIP_FILE); // add fileto zip archive
}
$archiveName = "backup_".date('m-d-Y H:i:s').".zip"; // name of the returned file
$zip->Flush(TBSZIP_DOWNLOAD, $archiveName); // flush the result as an HTTP download
这是在我的博客整个文章。
不隶属于 StackOverflow