/**
  * Create a new temporary file from an article file.
  * @param $articleFile object
  * @param $userId int
  * @return object The new TemporaryFile or false on failure
  */
 function articleToTemporaryFile($articleFile, $userId)
 {
     // Get the file extension, then rename the file.
     $fileExtension = $this->parseFileExtension($articleFile->getFileName());
     if (!$this->fileExists($this->filesDir, 'dir')) {
         // Try to create destination directory
         $this->mkdirtree($this->filesDir);
     }
     $newFileName = basename(tempnam($this->filesDir, $fileExtension));
     if (!$newFileName) {
         return false;
     }
     if (copy($articleFile->getFilePath(), $this->filesDir . $newFileName)) {
         $temporaryFileDao =& DAORegistry::getDAO('TemporaryFileDAO');
         $temporaryFile = new TemporaryFile();
         $temporaryFile->setUserId($userId);
         $temporaryFile->setFileName($newFileName);
         $temporaryFile->setFileType($articleFile->getFileType());
         $temporaryFile->setFileSize($articleFile->getFileSize());
         $temporaryFile->setOriginalFileName($articleFile->getOriginalFileName());
         $temporaryFile->setDateUploaded(Core::getCurrentDate());
         $temporaryFileDao->insertTemporaryFile($temporaryFile);
         return $temporaryFile;
     } else {
         return false;
     }
 }
예제 #2
0
 /**
  * Internal function to return a TemporaryFile object from a row.
  * @param $row array
  * @return TemporaryFile
  */
 function &_returnTemporaryFileFromRow(&$row)
 {
     $temporaryFile = new TemporaryFile();
     $temporaryFile->setId($row['file_id']);
     $temporaryFile->setFileName($row['file_name']);
     $temporaryFile->setFileType($row['file_type']);
     $temporaryFile->setFileSize($row['file_size']);
     $temporaryFile->setUserId($row['user_id']);
     $temporaryFile->setOriginalFileName($row['original_file_name']);
     $temporaryFile->setDateUploaded($this->datetimeFromDB($row['date_uploaded']));
     HookRegistry::call('TemporaryFileDAO::_returnTemporaryFileFromRow', array(&$temporaryFile, &$row));
     return $temporaryFile;
 }
 /**
  * Upload the file and add it to the database.
  * @param $fileName string index into the $_FILES array
  * @param $userId int
  * @return object The new TemporaryFile or false on failure
  */
 function handleUpload($fileName, $userId)
 {
     // Get the file extension, then rename the file.
     $fileExtension = $this->parseFileExtension($this->getUploadedFileName($fileName));
     if (!$this->fileExists($this->filesDir, 'dir')) {
         // Try to create destination directory
         $this->mkdirtree($this->filesDir);
     }
     $newFileName = basename(tempnam($this->filesDir, $fileExtension));
     if (!$newFileName) {
         return false;
     }
     if ($this->uploadFile($fileName, $this->filesDir . $newFileName)) {
         $temporaryFileDao =& DAORegistry::getDAO('TemporaryFileDAO');
         $temporaryFile = new TemporaryFile();
         $temporaryFile->setUserId($userId);
         $temporaryFile->setFileName($newFileName);
         $temporaryFile->setFileType($_FILES[$fileName]['type']);
         $temporaryFile->setFileSize($_FILES[$fileName]['size']);
         $temporaryFile->setOriginalFileName(TemporaryFileManager::truncateFileName($_FILES[$fileName]['name'], 127));
         $temporaryFile->setDateUploaded(Core::getCurrentDate());
         $temporaryFileDao->insertTemporaryFile($temporaryFile);
         return $temporaryFile;
     } else {
         return false;
     }
 }