Example #1
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();
     }
 }