コード例 #1
0
 /**
  * Download a file.
  * @param $fileId int the file id of the file to download
  * @param $revision int the revision of the file to download
  * @param $inline print file as inline instead of attachment, optional
  * @return boolean
  */
 function downloadFile($monographId, $fileId, $revision = null, $inline = false)
 {
     $returner = false;
     $monographFile =& MonographFileManager::_getFile($fileId, $revision);
     if (isset($monographFile)) {
         // Make sure that the file belongs to the monograph.
         if ($monographFile->getMonographId() != $monographId) {
             fatalError('Invalid file id!');
         }
         // Mark the file as viewed by this user.
         $sessionManager =& SessionManager::getManager();
         $session =& $sessionManager->getUserSession();
         $user =& $session->getUser();
         if (is_a($user, 'User')) {
             $viewsDao =& DAORegistry::getDAO('ViewsDAO');
             $viewsDao->recordView(ASSOC_TYPE_MONOGRAPH_FILE, $fileId, $user->getId());
         }
         // Send the file to the user.
         $filePath = $monographFile->getFilePath();
         $mediaType = $monographFile->getFileType();
         $returner = parent::downloadFile($filePath, $mediaType, $inline);
     }
     return $returner;
 }