Merge branch 'MDL-58281-file-missing-500' of https://github.com/brendanheywood/moodle

This commit is contained in:
Andrew Nicols
2020-01-07 11:30:30 +08:00
3 changed files with 24 additions and 8 deletions
+17 -7
View File
@@ -2219,20 +2219,20 @@ function readfile_accel($file, $mimetype, $accelerate) {
if ($ranges) {
if (is_object($file)) {
$handle = $file->get_content_file_handle();
if ($handle === false) {
throw new file_exception('storedfilecannotreadfile', $file->get_filename());
}
} else {
$handle = fopen($file, 'rb');
if ($handle === false) {
throw new file_exception('cannotopenfile', $file);
}
}
byteserving_send_file($handle, $mimetype, $ranges, $filesize);
}
}
}
header('Content-Length: '.$filesize);
if (!empty($_SERVER['REQUEST_METHOD']) and $_SERVER['REQUEST_METHOD'] === 'HEAD') {
exit;
}
if ($filesize > 10000000) {
// for large files try to flush and close all buffers to conserve memory
while(@ob_get_level()) {
@@ -2242,11 +2242,21 @@ function readfile_accel($file, $mimetype, $accelerate) {
}
}
// Send this header after we have flushed the buffers so that if we fail
// later can remove this because it wasn't sent.
header('Content-Length: ' . $filesize);
if (!empty($_SERVER['REQUEST_METHOD']) and $_SERVER['REQUEST_METHOD'] === 'HEAD') {
exit;
}
// send the whole file content
if (is_object($file)) {
$file->readfile();
} else {
readfile_allow_large($file, $filesize);
if (readfile_allow_large($file, $filesize) === false) {
throw new file_exception('cannotopenfile', $file);
}
}
}
+3 -1
View File
@@ -63,7 +63,9 @@ abstract class file_system {
} else {
$path = $this->get_remote_path_from_storedfile($file);
}
readfile_allow_large($path, $file->get_filesize());
if (readfile_allow_large($path, $file->get_filesize()) === false) {
throw new file_exception('storedfilecannotreadfile', $file->get_filename());
}
}
/**
+4
View File
@@ -362,6 +362,10 @@ function default_exception_handler($ex) {
$info = get_exception_info($ex);
// If we already tried to send the header remove it, the content length
// should be either empty or the length of the error page.
@header_remove('Content-Length');
if (is_early_init($info->backtrace)) {
echo bootstrap_renderer::early_error($info->message, $info->moreinfourl, $info->link, $info->backtrace, $info->debuginfo, $info->errorcode);
} else {