Merge branch 'MDL-38194-master' of git://github.com/sammarshallou/moodle
Conflicts: lib/upgrade.txt
This commit is contained in:
+38
-1
@@ -1959,6 +1959,43 @@ function send_header_404() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The readfile function can fail when files are larger than 2GB (even on 64-bit
|
||||
* platforms). This wrapper uses readfile for small files and custom code for
|
||||
* large ones.
|
||||
*
|
||||
* @param string $path Path to file
|
||||
* @param int $filesize Size of file (if left out, will get it automatically)
|
||||
* @return int|bool Size read (will always be $filesize) or false if failed
|
||||
*/
|
||||
function readfile_allow_large($path, $filesize = -1) {
|
||||
// Automatically get size if not specified.
|
||||
if ($filesize === -1) {
|
||||
$filesize = filesize($path);
|
||||
}
|
||||
if ($filesize <= 2147483647) {
|
||||
// If the file is up to 2^31 - 1, send it normally using readfile.
|
||||
return readfile($path);
|
||||
} else {
|
||||
// For large files, read and output in 64KB chunks.
|
||||
$handle = fopen($path, 'r');
|
||||
if ($handle === false) {
|
||||
return false;
|
||||
}
|
||||
$left = $filesize;
|
||||
while ($left > 0) {
|
||||
$size = min($left, 65536);
|
||||
$buffer = fread($handle, $size);
|
||||
if ($buffer === false) {
|
||||
return false;
|
||||
}
|
||||
echo $buffer;
|
||||
$left -= $size;
|
||||
}
|
||||
return $filesize;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enhanced readfile() with optional acceleration.
|
||||
* @param string|stored_file $file
|
||||
@@ -2081,7 +2118,7 @@ function readfile_accel($file, $mimetype, $accelerate) {
|
||||
if (is_object($file)) {
|
||||
$file->readfile();
|
||||
} else {
|
||||
readfile($file);
|
||||
readfile_allow_large($file, $filesize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -409,7 +409,7 @@ class stored_file {
|
||||
throw new file_exception('storedfilecannotread', '', $path);
|
||||
}
|
||||
}
|
||||
readfile($path);
|
||||
readfile_allow_large($path, $this->get_filesize());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,6 +35,7 @@ information provided here is intended especially for developers.
|
||||
* Internal (noreply and support) user support has been added for sending/receiving message.
|
||||
Use core_user::get_noreply_user() and core_user::get_support_user() to get noreply and support user's respectively.
|
||||
Real users can be used as noreply/support users by setting $CFG->noreplyuserid and $CFG->supportuserid
|
||||
* New function readfile_allow_large() in filelib.php for use when very large files may need sending to user.
|
||||
|
||||
DEPRECATIONS:
|
||||
Various previously deprecated functions have now been altered to throw DEBUG_DEVELOPER debugging notices
|
||||
|
||||
Reference in New Issue
Block a user