Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function addDocument($title, $date, $file, $subject_id) {
- if (!Validation::validTitle($title)) {
- throw new InvalidInputException(Messages::$invalid_title);
- }
- if (!Validation::validDate($date)) {
- throw new InvalidInputException(Messages::$invalid_date);
- }
- if ($file["name"] == null) {
- throw new InvalidInputException(Messages::$no_file);
- }
- if ($file["error"] > 0) {
- $error = $file["error"];
- switch ($error) {
- case 1: $message = Messages::$file_too_big; break;
- default: $message = Messages::$system_error;
- }
- throw new InvalidInputException($message);
- } else {
- //$extension = end(explode(".", $file["name"]));
- $extension = strtoupper(substr(strrchr($file["name"],'.'),1));
- if (!Validation::validFileType($extension)) {
- throw new InvalidInputException(Messages::$invalid_extension);
- }
- if ($file["size"] > Config::$max_file_size*1024*1024) {
- throw new InvalidInputException(Messages::$file_too_big);
- }
- $file["name"] = time()."_".$file["name"];
- move_uploaded_file($file["tmp_name"], "../uploads/" . $file["name"]);
- $file_name = $file["name"];
- $size = $file["size"];
- $sql = "INSERT INTO documents
- (title, date, file_name, extension, size, subject_id)
- VALUES
- ('$title','$date','$file_name','$extension','$size','$subject_id')";
- $result = $this->query($sql);
- if (!$result) {
- throw new DatabaseErrorException(mysql_error());
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement