Commit 82c224ee authored by David Mudrák's avatar David Mudrák
Browse files

MDL-32471 send_stored_file() now supports the preview option

If for any reason the preview image can't be generated for the given
file (eg we do not support its mimetype yet), the function will send
404 Not Found HTTP header. This will be useful for the lazy loading of
the file thumbnails as the JavaScript will simply ignore such response
and will not replace the default icon for the file.

In the future, a fallback thumbnail generator can be implemented that
would generate some sort of default preview for all files (eg using
the mimetype icon like some desktop OS do).
parent c4d19c5a
......@@ -1984,6 +1984,23 @@ function send_stored_file($stored_file, $lifetime=86400 , $filter=0, $forcedownl
$dontdie = true;
}
if (!empty($options['preview'])) {
// replace the file with its preview
$fs = get_file_storage();
$stored_file = $fs->get_file_preview($stored_file, $options['preview']);
if (!$stored_file) {
// unable to create a preview of the file
send_header_404();
die();
} else {
// preview images have fixed cache lifetime and they ignore forced download
// (they are generated by GD and therefore they are considered reasonably safe).
$lifetime = DAYSECS;
$filter = 0;
$forcedownload = false;
}
}
if (!$stored_file or $stored_file->is_directory()) {
// nothing to serve
if ($dontdie) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment