本文整理汇总了PHP中DataGenerator::isPromptDownloadZipped方法的典型用法代码示例。如果您正苦于以下问题:PHP DataGenerator::isPromptDownloadZipped方法的具体用法?PHP DataGenerator::isPromptDownloadZipped怎么用?PHP DataGenerator::isPromptDownloadZipped使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataGenerator
的用法示例。
在下文中一共展示了DataGenerator::isPromptDownloadZipped方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: DataGenerator
<?php
require_once __DIR__ . "/library.php";
Core::init("generation");
$gen = new DataGenerator(Constants::GEN_ENVIRONMENT_POST, $_POST);
$response = $gen->generate();
if ($gen->getExportTarget() == "promptDownload") {
header("Cache-Control: private, no-cache, must-revalidate");
// check if user opted to zip the generated data
if ($gen->isPromptDownloadZipped()) {
$randNum = mt_rand(0, 100000000);
$fileName = $randNum . "_" . $response["promptDownloadFilename"];
$zipPath = $filePath . ".zip";
if (file_put_contents($fileName, $response["content"])) {
// now that we've written the file, zip it up
$zip = new ZipArchive();
$zipFile = $zip->open($zipPath, ZipArchive::CREATE);
if ($zipFile && $zip->addFile($fileName, $response["promptDownloadFilename"])) {
// we've got our zip file now we may set the response header
$zip->close();
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=" . $response["promptDownloadFilename"] . ".zip");
readfile($zipPath);
unlink($zipPath);
unlink($fileName);
exit;
}
}
// no compression, send the original data back
} else {
header("Content-Type: {$response["contentTypeHeader"]}");