Created
September 20, 2016 17:05
-
-
Save KenanMurad/7a281d236e3b0ea1b41073bf195c89f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
commented
Sep 20, 2016
= 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