本文整理汇总了PHP中readfile_allow_large函数的典型用法代码示例。如果您正苦于以下问题:PHP readfile_allow_large函数的具体用法?PHP readfile_allow_large怎么用?PHP readfile_allow_large使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readfile_allow_large函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readfile_accel
//.........这里部分代码省略.........
header('Content-Type: ' . $mimetype);
}
$lastmodified = is_object($file) ? $file->get_timemodified() : filemtime($file);
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT');
if (is_object($file)) {
header('Etag: "' . $file->get_contenthash() . '"');
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) and trim($_SERVER['HTTP_IF_NONE_MATCH'], '"') === $file->get_contenthash()) {
header('HTTP/1.1 304 Not Modified');
return;
}
}
// if etag present for stored file rely on it exclusively
if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) and (empty($_SERVER['HTTP_IF_NONE_MATCH']) or !is_object($file))) {
// get unixtime of request header; clip extra junk off first
$since = strtotime(preg_replace('/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"]));
if ($since && $since >= $lastmodified) {
header('HTTP/1.1 304 Not Modified');
return;
}
}
if ($accelerate and !empty($CFG->xsendfile)) {
if (empty($CFG->disablebyteserving) and $mimetype !== 'text/plain') {
header('Accept-Ranges: bytes');
} else {
header('Accept-Ranges: none');
}
if (is_object($file)) {
$fs = get_file_storage();
if ($fs->xsendfile($file->get_contenthash())) {
return;
}
} else {
require_once "{$CFG->libdir}/xsendfilelib.php";
if (xsendfile($file)) {
return;
}
}
}
$filesize = is_object($file) ? $file->get_filesize() : filesize($file);
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT');
if ($accelerate and empty($CFG->disablebyteserving) and $mimetype !== 'text/plain') {
header('Accept-Ranges: bytes');
if (!empty($_SERVER['HTTP_RANGE']) and strpos($_SERVER['HTTP_RANGE'], 'bytes=') !== FALSE) {
// byteserving stuff - for acrobat reader and download accelerators
// see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
// inspired by: http://www.coneural.org/florian/papers/04_byteserving.php
$ranges = false;
if (preg_match_all('/(\\d*)-(\\d*)/', $_SERVER['HTTP_RANGE'], $ranges, PREG_SET_ORDER)) {
foreach ($ranges as $key => $value) {
if ($ranges[$key][1] == '') {
//suffix case
$ranges[$key][1] = $filesize - $ranges[$key][2];
$ranges[$key][2] = $filesize - 1;
} else {
if ($ranges[$key][2] == '' || $ranges[$key][2] > $filesize - 1) {
//fix range length
$ranges[$key][2] = $filesize - 1;
}
}
if ($ranges[$key][2] != '' && $ranges[$key][2] < $ranges[$key][1]) {
//invalid byte-range ==> ignore header
$ranges = false;
break;
}
//prepare multipart header
$ranges[$key][0] = "\r\n--" . BYTESERVING_BOUNDARY . "\r\nContent-Type: {$mimetype}\r\n";
$ranges[$key][0] .= "Content-Range: bytes {$ranges[$key][1]}-{$ranges[$key][2]}/{$filesize}\r\n\r\n";
}
} else {
$ranges = false;
}
if ($ranges) {
if (is_object($file)) {
$handle = $file->get_content_file_handle();
} else {
$handle = fopen($file, 'rb');
}
byteserving_send_file($handle, $mimetype, $ranges, $filesize);
}
}
} else {
// Do not byteserve
header('Accept-Ranges: none');
}
header('Content-Length: ' . $filesize);
if ($filesize > 10000000) {
// for large files try to flush and close all buffers to conserve memory
while (@ob_get_level()) {
if (!@ob_end_flush()) {
break;
}
}
}
// send the whole file content
if (is_object($file)) {
$file->readfile();
} else {
readfile_allow_large($file, $filesize);
}
}
示例2: readfile
/**
* Dumps file content to page.
*/
public function readfile()
{
$path = $this->get_content_file_location();
if (!is_readable($path)) {
if (!$this->fs->try_content_recovery($this) or !is_readable($path)) {
throw new file_exception('storedfilecannotread', '', $path);
}
}
readfile_allow_large($path, $this->get_filesize());
}