/**
  * Download file from server
  *
  * @param Gpf_Rpc_Params $params
  * @service db_file read
  */
 public function download(Gpf_Rpc_Params $params)
 {
     try {
         $form = new Gpf_Rpc_Form($params);
         if (!strlen($form->getFieldValue('fileid'))) {
             throw new Gpf_Exception("No fileid specified");
         }
         $this->file = new Gpf_Db_File();
         $this->file->set('fileid', $form->getFieldValue("fileid"));
         $this->file->load();
         try {
             if ($form->getFieldValue('attachment') == Gpf::YES) {
                 $this->isAttachment = true;
             } else {
                 $this->isAttachment = false;
             }
         } catch (Exception $e) {
             $this->isAttachment = false;
         }
     } catch (Gpf_DbEngine_NoRow $e) {
         throw new Exception($this->_("File does not exist"));
     } catch (Exception $e) {
         throw new Exception($e->getMessage());
     }
     return $this;
 }
示例#2
0
 /**
  * Delete uploaded file from database or files directory
  *
  * @service uploaded_file delete
  * @param Gpf_Rpc_Params $params
  * @return Gpf_Rpc_Action
  */
 public function deleteFile(Gpf_Rpc_Params $params)
 {
     $action = new Gpf_Rpc_Action($params);
     if ($action->existsParam('fileid') && $action->getParam('fileid') != '') {
         $dbRow = new Gpf_Db_File();
         $dbRow->setFileId($action->getParam('fileid'));
         try {
             $dbRow->load();
         } catch (Gpf_DbEngine_NoRow $e) {
             throw new Exception($this->_("Failed to delete file. File doesn't exist in database."));
         }
         try {
             $dbRow->delete();
         } catch (Gpf_Exception $e) {
             $action->addError();
             $action->setErrorMessage($this->_('Failed to delete file from database.'));
             return $action;
         }
     } else {
         $fileUrl = $action->getParam('fileurl');
         $fileName = substr($fileUrl, strrpos($fileUrl, '/') + 1);
         $file = new Gpf_Io_File(Gpf_Paths::getInstance()->getAccountDirectoryPath() . Gpf_Paths::FILES_DIRECTORY . $fileName);
         if (!$file->delete()) {
             $action->addError();
             $action->setErrorMessage($this->_('Failed to delete file.'));
         }
     }
     $action->addOk();
     return $action;
 }
    private function getFileName($fileId) {
		$file = new Gpf_Db_File();
		$file->setFileId($fileId);
		$file->load();
		return $file->getFileName();
    }