Пример #1
0
 public function uploadFile($array)
 {
     if (!empty($array["title"])) {
         //Detect type
         if (empty($_FILES["FileInput"]['size']) && empty($array["LinkInput"])) {
             throw new Exception("Set either a file source or link");
         } elseif (empty($_FILES["FileInput"]['size'])) {
             $is_link = true;
         } elseif (empty($array["LinkInput"])) {
             $is_link = false;
         } else {
             //Both set
             throw new Exception("Set either a file source or link not both");
         }
         //Upload
         if (!$is_link) {
             $uploader = new AnyFileUploader("FileInput", $array["title"]);
             $ok = $uploader->upload();
             $error = $ok ? "" : "Oops! Something went wrong! Upload failed";
         } else {
             $ok = filter_var($array["LinkInput"], FILTER_VALIDATE_URL);
             $error = $ok ? "" : "Invalid link";
         }
         if ($error) {
             throw new Exception($error);
         }
         //Save meta data
         $link = AdminUtility::getDefaultDBConnection();
         $query = "insert into library set " . "title = '{$array['title']}', " . "author = '{$array['author']}', " . "publisher = '{$array['publisher']}', " . "date_published = '{$array['date_published']}', " . "isbn = '{$array['isbn']}', " . "category = '{$array['category']}', " . "sub_category = '{$array['sub_category']}', " . "keywords = '{$array['keywords']}', " . "contributor = '{$array['contributor']}', " . "file_type = '" . (isset($uploader) ? $uploader->getExtension() : 'link') . "', " . "link = '" . (isset($uploader) ? $uploader->getFileLink() : $array['LinkInput']) . "'";
         $res = mysqli_query($link, $query);
         AdminUtility::logMySQLError($link);
         return $res ? "Upload Successful!" : "Oops! Something went wrong. Database didn't respond very well";
     } else {
         throw new Exception("Title not set");
     }
 }
 function __construct($input_name, $output_file_name, $upload_directory = LIBRARY_UPLOAD_DIR)
 {
     parent::__construct($input_name, $output_file_name);
     $this->setUploadDirectory($upload_directory);
     $this->setSupportedMIME_types(AnyFileUploader::MIME());
 }