*/
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.
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
$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;