Имеется папка с файлами и скрипт создания архива. Необходимо чтобы при изменении файлов в папке архив пересоздавался, если изменений никаких не будет, то оставался старый архив.
Как всё это можно реализовать?
<?
$grab=@file_get_contents("...путь до папки/version.ver");
$grab = ereg_replace('(.*)ENGINE2]','', $grab);
if ($grab!="") {
eregi("date=([0-9\.]+)",$grab,$pocket2);
$date="{$pocket2[1]}";
}
else {
$date="Невозможно прочитать.";
}
$now = date('d.m.Y');
if ($date = $now) {
sleep(1);
}
else {
class ZipFolder {
protected $zip;
protected $root;
protected $ignored_names;
function __construct($file, $folder, $ignored=null) {
$this->zip = new ZipArchive();
$this->ignored_names = is_array($ignored) ? $ignored : $ignored ? array($ignored) : array();
if ($this->zip->open($file, ZIPARCHIVE::CREATE)!==TRUE) {
throw new Exception("cannot open <$file>\n");
}
$folder = substr($folder, -1) == '/' ? substr($folder, 0, strlen($folder)-1) : $folder;
if(strstr($folder, '/')) {
$this->root = substr($folder, 0, strrpos($folder, '/')+1);
$folder = substr($folder, strrpos($folder, '/')+1);
}
$this->zip($folder);
$this->zip->close();
}
function zip($folder, $parent=null) {
$full_path = $this->root.$parent.$folder;
$zip_path = $parent.$folder;
$this->zip->addEmptyDir($zip_path);
$dir = new DirectoryIterator($full_path);
foreach($dir as $file) {
if(!$file->isDot()) {
$filename = $file->getFilename();
if(!in_array($filename, $this->ignored_names)) {
if($file->isDir()) {
$this->zip($filename, $zip_path.'/');
}
else {
$this->zip->addFile($full_path.'/'.$filename, $zip_path.'/'.$filename);
}
}
}
}
}
}
// full path used to demonstrate it's root-path stripping ability
$zip = new ZipFolder('...путь до архива.../archiv.zip', '...путь до папки...', '');
}
?>
<?
$grab=@file_get_contents("...путь до папки/version.ver");
$grab = ereg_replace('(.*)ENGINE2]','', $grab);
if ($grab!="") {
eregi("date=([0-9\.]+)",$grab,$pocket2);
$date="{$pocket2[1]}";
}
else {
$date="Невозможно прочитать.";
}
$now = date('d.m.Y');
if ($date = $now) {
class ZipFolder {
protected $zip;
protected $root;
protected $ignored_names;
function __construct($file, $folder, $ignored=null) {
$this->zip = new ZipArchive();
$this->ignored_names = is_array($ignored) ? $ignored : $ignored ? array($ignored) : array();
if ($this->zip->open($file, ZIPARCHIVE::CREATE)!==TRUE) {
throw new Exception("cannot open <$file>\n");
}
$folder = substr($folder, -1) == '/' ? substr($folder, 0, strlen($folder)-1) : $folder;
if(strstr($folder, '/')) {
$this->root = substr($folder, 0, strrpos($folder, '/')+1);
$folder = substr($folder, strrpos($folder, '/')+1);
}
$this->zip($folder);
$this->zip->close();
}
function zip($folder, $parent=null) {
$full_path = $this->root.$parent.$folder;
$zip_path = $parent.$folder;
$this->zip->addEmptyDir($zip_path);
$dir = new DirectoryIterator($full_path);
foreach($dir as $file) {
if(!$file->isDot()) {
$filename = $file->getFilename();
if(!in_array($filename, $this->ignored_names)) {
if($file->isDir()) {
$this->zip($filename, $zip_path.'/');
}
else {
$this->zip->addFile($full_path.'/'.$filename, $zip_path.'/'.$filename);
}
}
}
}
}
}
// full path used to demonstrate it's root-path stripping ability
$zip = new ZipFolder('...путь до архива.../archiv.zip', '...путь до папки...', '');
}
else {
sleep(1);
}
?>
if ($date = $now)
if ($date == $now)
if ($date == $now)
Rostov114 писал(а):Я вот не пойму. Нельзя чтоли найти нормальный скрипт зеркала NOD32?
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 56