示例#1
0
 protected function getContent()
 {
     $selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
     $selectBuilder->select->add('content');
     $selectBuilder->from->add(Gpf_Db_Table_FileContents::getName());
     $selectBuilder->where->add('fileid', '=', $this->file->getFileId());
     $selectBuilder->orderBy->add('contentid', true);
     $sth = $this->createDatabase()->execute($selectBuilder->toString());
     while ($row = $sth->fetchArray()) {
         echo $row['content'];
     }
     return '';
 }
示例#2
0
 /**
  * Deletes row. Primary key value must be set before this function is called
  */
 public function delete()
 {
     if ($this->isPrimaryKeyEmpty()) {
         throw new Gpf_Exception("Could not delete Row. Primary key values are empty");
     }
     $this->load();
     if ($this->getFileId() != "") {
         try {
             $file = new Gpf_Db_File();
             $file->setFileId($this->getFileId());
             $file->removeReference();
         } catch (Gpf_DbEngine_Driver_Mysql_SqlException $e) {
         }
     }
     return parent::delete();
 }
示例#3
0
 /**
  * Save content of uploaded file to database
  *
  * @param string $filename
  * @param Gpf_Db_File $file
  */
 private function uploadContent($filename, Gpf_Db_File $file)
 {
     $contentId = 1;
     $tmpFile = new Gpf_Io_File(get_cfg_var('upload_tmp_dir') . $filename);
     if (!$tmpFile->isExists()) {
         $tmpFile->setFileName($filename);
     }
     if (!$tmpFile->isExists()) {
         throw new Gpf_Exception("File not found " . $tmpFile->getFileName());
     }
     $tmpFile->open();
     while ($data = $tmpFile->read(500000)) {
         $fileContent = new Gpf_Db_FileContent();
         $fileContent->set('fileid', $file->get('fileid'));
         $fileContent->set('contentid', $contentId++);
         $fileContent->set('content', $data);
         $fileContent->save();
     }
 }
 /**
  * Print content of file to default output
  */
 private function downloadContent()
 {
     if ($this->printHeaders()) {
         $selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
         $selectBuilder->select->add('content', 'content');
         $selectBuilder->from->add(Gpf_Db_Table_FileContents::getName());
         $selectBuilder->where->add('fileid', '=', $this->file->get('fileid'));
         $selectBuilder->orderBy->add('contentid', true);
         $contents = $selectBuilder->getAllRows();
         foreach ($contents as $contentRecord) {
             echo $contentRecord->get('content');
         }
         return true;
     }
     return false;
 }
示例#5
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();
    }
示例#7
0
    protected function saveUploadedFile() {
        
        $file = new Gpf_Db_File();
        $file->set('filename', $this->name);
        $file->set('filesize', $this->size);
        $file->set('filetype', $this->type);
        $file->save();
             
        $dir = new Gpf_Io_File($this->getZipFolderUrl().$file->getFileId().'/');
        if ($dir->isExists()) {
            $dir->delete();
        }
        $dir->mkdir();
        $tmpZip = new Gpf_Io_File($this->getZipFolderUrl().$file->getFileId().'/'.$file->getFileId().".zip");
        $dir->copy(new Gpf_Io_File($this->tmpName),$tmpZip);
        
        $archive = new PclZip($this->getZipFolderUrl().$file->getFileId().'/'.$file->getFileId().".zip");
        $err = $archive->extract($this->getZipFolderUrl().$file->getFileId().'/');
        if ($err <= 0) {
            throw new Gpf_Exception("code: ".$err);
        }

        $tmpZip->delete();
 
        return $file;
    }
示例#8
0
 /**
  * @return Gpf_DbEngine_Row_Collection<Gpf_Db_File>
  */
 public function getAttachements()
 {
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->addAll(Gpf_Db_Table_Files::getInstance(), 'f');
     $select->from->add(Gpf_Db_Table_MailAttachments::getName(), 'ma');
     $select->from->addInnerJoin(Gpf_Db_Table_Files::getName(), 'f', 'ma.' . Gpf_Db_Table_MailAttachments::FILE_ID . ' = f.' . Gpf_Db_Table_Files::ID);
     $select->where->add("ma." . Gpf_Db_Table_Mails::ID, "=", $this->getId());
     $file = new Gpf_Db_File();
     return $file->loadCollectionFromRecordset($select->getAllRows());
 }