示例#1
0
 /**
  * Creates a zip file of the album
  *
  * @param string $albumname album folder
  * @param bool fromcache if true, images will be the "sized" image in the cache file
  */
 static function create($albumname, $fromcache)
 {
     global $_zp_zip_list, $_zp_gallery, $defaultSize;
     $album = newAlbum($albumname);
     if (!$album->isMyItem(LIST_RIGHTS) && !checkAlbumPassword($albumname)) {
         self::pageError(403, gettext("Forbidden"));
     }
     if (!$album->exists) {
         self::pageError(404, gettext('Album not found'));
     }
     $_zp_zip_list = array();
     if ($fromcache) {
         $opt = array('large_file_size' => 5 * 1024 * 1024, 'comment' => sprintf(gettext('Created from cached images of %1$s on %2$s.'), $album->name, zpFormattedDate(DATE_FORMAT, time())));
         loadLocalOptions(false, $_zp_gallery->getCurrentTheme());
         $defaultSize = getOption('image_size');
         self::AddAlbumCache($album, strlen($albumname), SERVERPATH . '/' . CACHEFOLDER . '/' . $albumname);
     } else {
         $opt = array('large_file_size' => 5 * 1024 * 1024, 'comment' => sprintf(gettext('Created from images in %1$s on %2$s.'), $album->name, zpFormattedDate(DATE_FORMAT, time())));
         self::AddAlbum($album, strlen($albumname), SERVERPATH . '/' . ALBUMFOLDER . '/' . $albumname);
     }
     $zip = new ZipStream($albumname . '.zip', $opt);
     foreach ($_zp_zip_list as $path => $file) {
         @set_time_limit(6000);
         $zip->add_file_from_path(internalToFilesystem($file), internalToFilesystem($path));
     }
     $zip->finish();
 }
示例#2
0
/**
 * Outputs a file for zip download
 * @param string $zipname name of the zip file
 * @param string $file the file to zip
 */
function putZip($zipname, $file)
{
    //we are dealing with file system items, convert the names
    $fileFS = internalToFilesystem($file);
    if (class_exists('ZipArchive')) {
        $zipfileFS = tempnam('', 'zip');
        $zip = new ZipArchive();
        $zip->open($zipfileFS, ZipArchive::CREATE);
        $zip->addFile($fileFS, basename($fileFS));
        $zip->close();
        ob_get_clean();
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: private", false);
        header("Content-Type: application/zip");
        header("Content-Disposition: attachment; filename=" . basename($zipname) . ";");
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: " . filesize($zipfileFS));
        readfile($zipfileFS);
        // remove zip file from temp path
        unlink($zipfileFS);
    } else {
        include_once SERVERPATH . '/' . ZENFOLDER . '/lib-zipStream.php';
        $zip = new ZipStream(internalToFilesystem($zipname));
        $zip->add_file_from_path(basename($fileFS), $fileFS);
        $zip->finish();
    }
}
示例#3
0
 public static function apiDownload(Request $r)
 {
     self::authenticateRequest($r);
     self::validateStats($r);
     // Get our runs
     $relevant_columns = array("run_id", "guid", "language", "status", "verdict", "runtime", "penalty", "memory", "score", "contest_score", "time", "submit_delay", "Users.username", "Problems.alias");
     try {
         $runs = RunsDAO::search(new Runs(array("contest_id" => $r["contest"]->getContestId())), "time", "DESC", $relevant_columns);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     $zip = new ZipStream($r["contest_alias"] . '.zip');
     // Add runs to zip
     $table = "guid,user,problem,verdict,points\n";
     foreach ($runs as $run) {
         $zip->add_file_from_path("runs/" . $run->getGuid(), RunController::getSubmissionPath($run));
         $columns[0] = 'username';
         $columns[1] = 'alias';
         $usernameProblemData = $run->asFilteredArray($columns);
         $table .= $run->getGuid() . "," . $usernameProblemData['username'] . "," . $usernameProblemData['alias'] . "," . $run->getVerdict() . "," . $run->getContestScore();
         $table .= "\n";
     }
     $zip->add_file("summary.csv", $table);
     // Add problem cases to zip
     $contest_problems = ContestProblemsDAO::GetRelevantProblems($r["contest"]->getContestId());
     foreach ($contest_problems as $problem) {
         $zip->add_file_from_path($problem->getAlias() . "_cases.zip", PROBLEMS_PATH . "/" . $problem->getAlias() . "/cases.zip");
     }
     // Return zip
     $zip->finish();
     die;
 }
 public static function apiDownload(Request $r)
 {
     self::authenticateRequest($r);
     self::validateStats($r);
     // Get our runs
     $relevant_columns = array('run_id', 'guid', 'language', 'status', 'verdict', 'runtime', 'penalty', 'memory', 'score', 'contest_score', 'time', 'submit_delay', 'Users.username', 'Problems.alias');
     try {
         $runs = RunsDAO::search(new Runs(array('contest_id' => $r['contest']->getContestId())), 'time', 'DESC', $relevant_columns);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     $zip = new ZipStream($r['contest_alias'] . '.zip');
     // Add runs to zip
     $table = "guid,user,problem,verdict,points\n";
     foreach ($runs as $run) {
         $zip->add_file_from_path('runs/' . $run->getGuid(), RunController::getSubmissionPath($run));
         $columns[0] = 'username';
         $columns[1] = 'alias';
         $usernameProblemData = $run->asFilteredArray($columns);
         $table .= $run->getGuid() . ',' . $usernameProblemData['username'] . ',' . $usernameProblemData['alias'] . ',' . $run->getVerdict() . ',' . $run->getContestScore();
         $table .= "\n";
     }
     $zip->add_file('summary.csv', $table);
     // Add problem cases to zip
     $contest_problems = ContestProblemsDAO::GetRelevantProblems($r['contest']->getContestId());
     foreach ($contest_problems as $problem) {
         $zip->add_file_from_path($problem->getAlias() . '_cases.zip', PROBLEMS_PATH . '/' . $problem->getAlias() . '/cases.zip');
     }
     // Return zip
     $zip->finish();
     die;
 }
示例#5
0
                        header("Pragma: public");
                        header("Expires: 0");
                        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                        header("Cache-Control: private", false);
                        header("Content-Type: application/zip");
                        header("Content-Disposition: attachment; filename=" . basename($zipname) . ";");
                        header("Content-Transfer-Encoding: binary");
                        header("Content-Length: " . filesize($zipname));
                        readfile($zipname);
                        // remove zip file from temp path
                        unlink($zipname);
                        exit;
                    } else {
                        include_once SERVERPATH . '/' . ZENFOLDER . '/lib-zipStream.php';
                        $zip = new ZipStream($zipname);
                        $zip->add_file_from_path(internalToFilesystem(basename($file)), internalToFilesystem($file));
                        $zip->finish();
                    }
                }
                break;
        }
    }
}
list($subtabs, $default) = getLogTabs();
$zenphoto_tabs['logs'] = array('text' => gettext("logs"), 'link' => WEBPATH . "/" . ZENFOLDER . '/admin-logs.php?page=logs', 'subtabs' => $subtabs, 'default' => $default);
printAdminHeader('logs', $default);
echo "\n</head>";
?>

<body>
示例#6
0
文件: main.php 项目: SlimBN/UploadIt
        throw new Exception('Permission denied');
    }
    $app['zadania_service']->delete($id);
    return new RedirectResponse($app['url_generator']->generate('home'));
})->before($checkUser)->bind('zadanie.delete')->convert('id', function ($id) {
    return (int) $id;
});
/**
 * Stahovanie zadani
 */
$app->get('/zadanie/{id}/zip', function (Silex\Application $app, $id) {
    error_reporting(0);
    $filelist = $app['zadania_service']->getFileList($id);
    $notelist = $app['zadania_service']->getNotes($id);
    $stream = function () use($filelist, $notelist, $id) {
        $zip = new ZipStream('zadanie_' . $id . '.zip');
        foreach ($notelist as $note) {
            if (empty($note['poznamka'])) {
                continue;
            }
            $zip->add_file('zadanie_' . $id . '/' . $note['login'] . '/poznamka.txt', $note['poznamka']);
        }
        foreach ($filelist as $subor) {
            $zip->add_file_from_path('zadanie_' . $id . '/' . $subor['login'] . '/' . $subor['nazov'], __DIR__ . '/uploads/' . $subor['cesta']);
        }
        $zip->finish();
    };
    return $app->stream($stream, 200, array('Content-Type' => 'application/zip'));
})->before($checkUser)->bind('zadanie.zip')->convert('id', function ($id) {
    return (int) $id;
});
示例#7
0
 /**
  * Creates a zip file of the album
  *
  * @param object $album album folder
  * @param string $zipname name of zip file
  * @param bool fromcache if true, images will be the "sized" image in the cache file
  */
 static function create($album, $zipname, $fromcache)
 {
     global $_zp_zip_list, $_zp_albums_visited_albumMenu, $_zp_gallery, $defaultSize;
     if (!$album->exists) {
         self::pageError(404, gettext('Album not found'));
     }
     if (!$album->checkAccess()) {
         self::pageError(403, gettext("Forbidden"));
     }
     $_zp_albums_visited_albumMenu = $_zp_zip_list = array();
     if ($fromcache) {
         $opt = array('large_file_size' => 5 * 1024 * 1024, 'comment' => sprintf(gettext('Created from cached images of %1$s on %2$s.'), $album->name, zpFormattedDate(DATE_FORMAT, time())));
         $defaultSize = getThemeOption('image_size', NULL, $_zp_gallery->getCurrentTheme());
     } else {
         $defaultSize = NULL;
         $opt = array('large_file_size' => 5 * 1024 * 1024, 'comment' => sprintf(gettext('Created from images in %1$s on %2$s.'), $album->name, zpFormattedDate(DATE_FORMAT, time())));
     }
     self::AddAlbum($album, $fromcache);
     if (class_exists('ZipArchive')) {
         $zipfileFS = tempnam('', 'zip');
         $zip = new ZipArchive();
         $zip->open($zipfileFS, ZipArchive::CREATE);
         foreach ($_zp_zip_list as $path => $file) {
             @set_time_limit(6000);
             $zip->addFile($path, internalToFilesystem(trim($file, '/')));
         }
         $zip->close();
         ob_get_clean();
         header("Pragma: public");
         header("Expires: 0");
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Cache-Control: private", false);
         header("Content-Type: application/zip");
         header("Content-Disposition: attachment; filename=" . basename($zipname . '.zip') . ";");
         header("Content-Transfer-Encoding: binary");
         header("Content-Length: " . filesize($zipfileFS));
         readfile($zipfileFS);
         // remove zip file from temp path
         unlink($zipfileFS);
     } else {
         require_once SERVERPATH . '/' . ZENFOLDER . '/lib-zipStream.php';
         $zip = new ZipStream(internalToFilesystem($zipname) . '.zip', $opt);
         foreach ($_zp_zip_list as $path => $file) {
             @set_time_limit(6000);
             $zip->add_file_from_path(internalToFilesystem($file), $path);
         }
         $zip->finish();
     }
 }