Skip to content

Commit

Permalink
file.php now calculates content-length correctly for filtered text an…
Browse files Browse the repository at this point in the history
…d HTML files.

Bug 1240
  • Loading branch information
moodler committed Apr 26, 2004
1 parent 3315ee3 commit e5890e7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions file.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,30 @@
header("Cache-control: max_age = $CFG->filelifetime");
header("Pragma: ");
header("Content-disposition: inline; filename=$filename");
header("Content-length: ".filesize($pathname));


if (empty($CFG->filteruploadedfiles)) {
header("Content-length: ".filesize($pathname));
header("Content-type: $mimetype");
readfile($pathname);

} else { /// Try and put the file through filters
if ($mimetype == "text/html") {
$output = format_text(implode('', file($pathname)), FORMAT_HTML, NULL, $courseid);

header("Content-length: ".strlen($output));
header("Content-type: text/html");
echo format_text(implode('', file($pathname)), FORMAT_HTML, NULL, $courseid);
echo $output;

} else if ($mimetype == "text/plain") {
header("Content-type: text/html");
$options->newlines = false;
echo "<pre>";
echo format_text(implode('', file($pathname)), FORMAT_MOODLE, $options, $courseid);
echo "</pre>";
$output = '<pre>'.format_text(implode('', file($pathname)), FORMAT_MOODLE, $options, $courseid).'</pre>';
header("Content-length: ".strlen($output));
header("Content-type: text/html");
echo $output;

} else { /// Just send it out raw
header("Content-length: ".filesize($pathname));
header("Content-type: $mimetype");
readfile($pathname);
}
Expand Down

0 comments on commit e5890e7

Please sign in to comment.