diff --git a/lib/filelib.php b/lib/filelib.php index eebedb09b56..ea0e4fcd8d6 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -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) {