本文整理汇总了PHP中OC_Helper::tmpFileNoClean方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Helper::tmpFileNoClean方法的具体用法?PHP OC_Helper::tmpFileNoClean怎么用?PHP OC_Helper::tmpFileNoClean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Helper
的用法示例。
在下文中一共展示了OC_Helper::tmpFileNoClean方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* return the content of a file or return a zip file containning multiply files
*
* @param dir $dir
* @param file $file ; seperated list of files to download
* @param boolean $only_header ; boolean to only send header of the request
*/
public static function get($dir, $files, $only_header = false)
{
$xsendfile = false;
if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) {
$xsendfile = true;
}
if (strpos($files, ';')) {
$files = explode(';', $files);
}
if (is_array($files)) {
self::validateZipDownload($dir, $files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
if ($xsendfile) {
$filename = OC_Helper::tmpFileNoClean('.zip');
} else {
$filename = OC_Helper::tmpFile('.zip');
}
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
exit("cannot open <{$filename}>\n");
}
foreach ($files as $file) {
$file = $dir . '/' . $file;
if (OC_Filesystem::is_file($file)) {
$tmpFile = OC_Filesystem::toTmpFile($file);
self::$tmpFiles[] = $tmpFile;
$zip->addFile($tmpFile, basename($file));
} elseif (OC_Filesystem::is_dir($file)) {
self::zipAddDir($file, $zip);
}
}
$zip->close();
set_time_limit($executionTime);
} elseif (OC_Filesystem::is_dir($dir . '/' . $files)) {
self::validateZipDownload($dir, $files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
if ($xsendfile) {
$filename = OC_Helper::tmpFileNoClean('.zip');
} else {
$filename = OC_Helper::tmpFile('.zip');
}
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
exit("cannot open <{$filename}>\n");
}
$file = $dir . '/' . $files;
self::zipAddDir($file, $zip);
$zip->close();
set_time_limit($executionTime);
} else {
$zip = false;
$filename = $dir . '/' . $files;
}
OC_Util::obEnd();
if ($zip or OC_Filesystem::is_readable($filename)) {
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
header('Content-Transfer-Encoding: binary');
OC_Response::disableCaching();
if ($zip) {
ini_set('zlib.output_compression', 'off');
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($filename));
self::addSendfileHeader($filename);
} else {
header('Content-Type: ' . OC_Filesystem::getMimeType($filename));
$storage = OC_Filesystem::getStorage($filename);
if ($storage instanceof OC_Filestorage_Local) {
self::addSendfileHeader(OC_Filesystem::getLocalFile($filename));
}
}
} elseif ($zip or !OC_Filesystem::file_exists($filename)) {
header("HTTP/1.0 404 Not Found");
$tmpl = new OC_Template('', '404', 'guest');
$tmpl->assign('file', $filename);
$tmpl->printPage();
} else {
header("HTTP/1.0 403 Forbidden");
die('403 Forbidden');
}
if ($only_header) {
if (!$zip) {
header("Content-Length: " . OC_Filesystem::filesize($filename));
}
return;
}
if ($zip) {
$handle = fopen($filename, 'r');
if ($handle) {
$chunkSize = 8 * 1024;
// 1 MB chunks
while (!feof($handle)) {
//.........这里部分代码省略.........