function student_files_handle_download

6.x student_files.module student_files_handle_download($student_id, $fid)

This actually finds and downloads the file for the user, decrypting if necessary.

File

modules/student_files/student_files.module, line 384
This is the student_files module, which will facilitate uploading (securely) files to be associated with student accounts.

Code

function student_files_handle_download($student_id, $fid) {

  $files_array = student_files_get_files_for_student($student_id);
  $file = @$files_array [$fid];

  if (!$file) {
    display_not_found();
    die;
  }

  // Otherwise, now we proceed.
  $file_contents = file_get_contents($file ["filepath"] . "/" . $file ["filename"]);

  if ($file ["is_encrypted"] == 1 && function_exists("encryption_decrypt")) {
    $file_contents = encryption_decrypt($file_contents);
  }

  // Okay, now let's spit it out to the browser for download.
  header('Content-type: ' . $file ["filetype"]);
  header('Content-Disposition: attachment; filename="' . $file ["original_filename"] . '"');
  print $file_contents;

  die;

}