Skip to content

Commit

Permalink
MDL-14589 new file not found general function
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 3, 2008
1 parent ede057f commit 2aea0c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
10 changes: 2 additions & 8 deletions draftfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

switch ($filearea) {
case 'user_draft' : $itemid = (int)array_shift($args); break;
default: not_found();
default: send_file_not_found();
}

$relativepath = '/'.implode('/', $args);
Expand All @@ -54,17 +54,11 @@
$fullpath = $context->id.$filearea.$itemid.$relativepath;

if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->get_filename() == '.') {
not_found();
send_file_not_found();
}

// ========================================
// finally send the file
// ========================================
session_write_close(); // unlock session during fileserving
send_stored_file($file, 0, false, $forcedownload);

function not_found() {
global $CFG;
header('HTTP/1.0 404 not found');
print_error('filenotfound', 'error', $CFG->wwwroot.'/'); //this is not displayed on IIS??
}
10 changes: 2 additions & 8 deletions userfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
switch ($filearea) {
case 'private': $itemid = 0; $forcedownload = true; break;
case 'draft' : $itemid = (int)array_shift($args); break;
default: not_found();
default: send_file_not_found();
}

$relativepath = '/'.implode('/', $args);
Expand All @@ -55,17 +55,11 @@
$fullpath = $context->id.$filearea.$itemid.$relativepath;

if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->get_filename() == '.') {
not_found();
send_file_not_found();
}

// ========================================
// finally send the file
// ========================================
session_write_close(); // unlock session during fileserving
send_stored_file($file, 0, false, $forcedownload);

function not_found() {
global $CFG;
header('HTTP/1.0 404 not found');
print_error('filenotfound', 'error', $CFG->wwwroot.'/'); //this is not displayed on IIS??
}

0 comments on commit 2aea0c5

Please sign in to comment.