function student_files_handle_delete

7.x student_files.module student_files_handle_delete($student_id, $fid)
6.x student_files.module student_files_handle_delete($student_id, $fid)

File

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

Code

function student_files_handle_delete($student_id, $fid) {
  // Get the file's information so we can unlink it from the file system.

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

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

  // Otherwise, now we proceed.
  if (!unlink($file ["filepath"] . "/" . $file ["filename"])) {
    // Couldn't delete for some reason.
    fp_add_message(t("Unable to delete file:") . " " . $file ["filepath"] . "/" . $file ["filename"] . t("
                      Possibly a file permission issue on server, or file already deleted.  If this problem continues, contact
                      your server administrator."), "error");

  }
  else {
    // We DID delete sucessfully, let's get rid of it from our db table.
    db_query("DELETE FROM student_files WHERE fid = ?", $fid);
    fp_add_message(t("File deleted successfully."));
  }

  // Return to the history page.
  fp_goto("history", "current_student_id=$student_id");

}