Skip to content

Instantly share code, notes, and snippets.

@KenanMurad
Created September 20, 2016 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KenanMurad/7a281d236e3b0ea1b41073bf195c89f1 to your computer and use it in GitHub Desktop.
Save KenanMurad/7a281d236e3b0ea1b41073bf195c89f1 to your computer and use it in GitHub Desktop.
<?php
require_once "vendor/autoload.php";
/**
* Created by PhpStorm.
* User: namel
* Date: 9/19/2016
* Time: 8:48 PM
*/
list($starDate, $endDate) = explode('-', $_GET['dates']);
if (strtotime($dates[0]) >= strtotime($dates[1])) {
throw new Exception('Dates wrong');
}
$begin = new DateTime($starDate);
$end = new DateTime($endDate);
$end = $end->modify('+1 day');
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval, $end);
$command = 'tar czf archive.tar.gz ';
foreach ($daterange as $date) {
$command .= $date->format("Y.m.d") . ' ';
}
echo $command;
//-- process starts
/*
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
$process = new Process($command);
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();*/
@nalekberov
Copy link

= strtotime($dates[1])) { throw new Exception('Dates wrong'); } $begin = new DateTime($dates[0]); $end = new DateTime($dates[1]); $end = $end->modify('+1 day'); $interval = new DateInterval('P1D'); $daterange = new DatePeriod($begin, $interval, $end); $command = 'tar czf archive.tar.gz '; foreach ($daterange as $date) { $command .= $date->format("Y.m.d") . ' '; } $process = new Process($command); $process->run(); // executes after the command finishes if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } echo $process->getOutput();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment