public function actionGetLast()
 {
     $domainName = filter_input(INPUT_GET, 'domain_name');
     $response = Api_Component_Factory::createResponse();
     if (!$this->isHaveAccessForDomain(self::GET_LAST_ACTION, $domainName, INPUT_GET)) {
         $response->setError(true)->setSuccess(false)->addMessage("access denied");
         http_response_code(403);
         echo $this->renderView('json', array('data' => $response->getData()));
         Api_Core_Application::end();
     }
     $helper = new Api_Application_Api_Helper_Backup();
     $storage = Api_Component_Factory::createFileStorage();
     $files = $helper->getLastFileUrl($domainName, $storage);
     $lastFile = end($files);
     if (empty($lastFile)) {
         $response->setError(true)->setSuccess(false)->addMessage("file not found");
         http_response_code(404);
         echo $this->renderView('json', array('data' => $response->getData()));
     } else {
         $url = $storage->getFileUrl($lastFile["file"]);
         if (ob_get_level()) {
             ob_end_clean();
         }
         header('Content-Type: application/octet-stream');
         header('Content-Disposition: attachment; filename="' . basename($lastFile["file"]) . '"');
         header('Content-transfer-encoding: binary');
         // Required? Not sure..
         set_time_limit(60 * 50);
         if ($fd = fopen($url, 'r')) {
             while (!feof($fd)) {
                 print fread($fd, 1024);
             }
             fclose($fd);
         }
         $storage->closeFileUrl($lastFile["file"]);
         Api_Core_Application::end();
     }
 }
Exemple #2
0
<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);
$root = realpath(__DIR__);
require_once $root . '/autoload.php';
set_time_limit(0);
ignore_user_abort(true);
$configData = (include $root . '/configs/config.php');
Api_Core_Application::init($configData);
$backup = new Job_Backup('dev1vika1');
$backup->run();
die;
$amazon = Api_Component_Factory::createFileStorage();
$files = $amazon->getFiles('**/2016.03.04');
$lastFile = end($files);
if (!empty($lastFile)) {
    $url = $amazon->getFileUrl($lastFile["file"]);
    //var_dump($url, basename($url), basename($lastFile["file"])); die();
    if (ob_get_level()) {
        ob_end_clean();
    }
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . basename($lastFile["file"]) . '"');
    header('Content-transfer-encoding: binary');
    // Required? Not sure..
    set_time_limit(60 * 28);
    if ($fd = fopen($url, 'r')) {
        while (!feof($fd)) {
            print fread($fd, 1024);
        }
 /**
  * 
  * @param string $domainName
  * @return \Job_Backup_Storage
  */
 static function createStorage($domainName)
 {
     $config = Api_Core_Factory::createConfig()->getConfig();
     $storage = Api_Component_Factory::createFileStorage();
     return new Job_Backup_Storage($domainName, $storage);
 }