From: Dan Marsden Date: Thu, 22 Mar 2012 20:58:52 +0000 (+1300) Subject: MDL-32147 - use correct 404 for server type X-Git-Tag: v2.3.0-beta~878^2 X-Git-Url: http://git.moodle.org/gw?p=moodle.git;a=commitdiff_plain;h=dbdc7355598e437e65ba17d59940dcc1ab33e0de MDL-32147 - use correct 404 for server type --- diff --git a/lib/filelib.php b/lib/filelib.php index 43bc8ddd242..1d0b01ccd2f 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -1596,9 +1596,19 @@ function get_mimetype_description($mimetype, $capitalise=false) { */ function send_file_not_found() { global $CFG, $COURSE; - header('HTTP/1.0 404 not found'); + send_header_404(); print_error('filenotfound', 'error', $CFG->wwwroot.'/course/view.php?id='.$COURSE->id); //this is not displayed on IIS?? } +/** + * Helper function to send correct 404 for server. + */ +function send_header_404() { + if (substr(php_sapi_name(), 0, 3) == 'cgi') { + header("Status: 404 Not Found"); + } else { + header('HTTP/1.0 404 not found'); + } +} /** * Check output buffering settings before sending file. @@ -1651,7 +1661,7 @@ function send_temp_file($path, $filename, $pathisstring=false) { if (!$pathisstring) { if (!file_exists($path)) { - header('HTTP/1.0 404 not found'); + send_header_404(); print_error('filenotfound', 'error', $CFG->wwwroot.'/'); } // executed after normal finish or abort diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 2561b20c7df..143d98b2708 100644 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -924,7 +924,7 @@ function scorm_pluginfile($course, $cm, $context, $filearea, $args, $forcedownlo $fs = get_file_storage(); if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { if ($filearea === 'content') { //return file not found straight away to improve performance. - header('HTTP/1.0 404 not found'); + send_header_404(); die; } return false;