Example #1
0
}
//get the id provided as a get parameter
if (!isset($_GET['id'])) {
    $message = urlencode("You are missing the file id.");
    header("Location: error.php?error={$message}");
    exit;
}
//if the id provided is not an actual id of a note in the database, error out
$note = Database::getNotesByID($_GET['id']);
if (!isset($note['id'])) {
    $message = urlencode("The file with the id provided does not exist.");
    header("Location: error.php?error={$message}");
    exit;
}
//if the note with the id provided is not an actual file, error out
$path = Database::getUploadPath($note['id'], $note['filetype']);
if (!file_exists($path)) {
    //Log the error so that the server knows a file is missing for a valid note
    Database::logError("File '{$path}' could not be found\n", false);
    $message = urlencode("The file could not be found.");
    header("Location: error.php?error={$message}");
    exit;
}
//tell browser to expect the mime type of whatever type the file is
$content = Database::getMimeFromType($note['filetype']);
header("Content-type:{$content}");
$fileName = $note['filename'];
//"Course_${note['courseID']}_${mysqldate}";
//tell the browser that the downloaded file's name should be the one in the database
header("Content-Disposition:attachment;filename=\"{$fileName}.{$note['filetype']}\"");
//output the files contents to the browser, allowing user to download file
Example #2
0
 public static function removeNoteFile($id)
 {
     $note = self::getNotesByID($id);
     if (!isset($note['id'])) {
         return false;
     }
     $path = Database::getUploadPath($note['id'], $note['filetype']);
     if (!file_exists($path)) {
         //Log the error so that the server knows a file is missing for a valid note
         Database::logError("File '{$path}' could not be found to be deleted\n", false);
         return false;
     }
     return unlink($path);
 }
Example #3
0
    exit;
}
$date = trim($_POST['date']);
$date = date("Y-m-d", strtotime($date));
$fileType = Config::$ALLOWED_TYPES[$mime];
$myName = "Lecture_{$date}";
$fileName = Database::sanitizeFileName($myName);
$id = Database::createNote($fileName, $fileType, $date, $course, $user);
$result = true;
//if the uploads folder does not exist, create it
if (!file_exists("./uploads")) {
    $result = mkdir("./uploads");
}
//if the upload has been created in the past at some point
if ($result === true) {
    $dir = Database::getUploadPath($id, $fileType);
    if (file_exists($dir)) {
        $message = urlencode("The file already exists on the server.");
        Database::logError("{$message}\n", false);
        header("Location: error.php?error={$message}");
        exit;
    }
    //move the uploaded file to the uploads folder under the name of its id
    move_uploaded_file($_FILES['file']['tmp_name'], $dir);
    //change the permissions on the uploaded file in the uploads folder to RW-R--R--
    chmod($dir, 0644);
    header("Location: in_class.php?id={$course}");
    exit;
} else {
    $message = urlencode("Could not create uploads folder.");
    Database::logError("{$message}\n", false);