/** * Upload the file and add it to the database. * @param $monographId integer * @param $fileName string index into the $_FILES array * @param $fileStage int monograph file stage (one of the MONOGRAPH_FILE_* constants) * @param $uploaderUserId int The id of the user that uploaded the file. * @param $uploaderUserGroupId int The id of the user group that the uploader acted in * when uploading the file. * @param $revisedFileId int ID of an existing file to revise * @param $genreId int foreign key into genres table (e.g. manuscript, etc.) * @param $assocType int * @param $assocId int * @return MonographFile the uploaded monograph file or null if an error occured. */ function &_handleUpload($monographId, $fileName, $fileStage, $uploaderUserId, $uploaderUserGroupId, $revisedFileId = null, $genreId = null, $assocId = null, $assocType = null) { $nullVar = null; // Ensure that the file has been correctly uploaded to the server. if (!MonographFileManager::uploadedFileExists($fileName)) { return $nullVar; } // Retrieve the location of the uploaded file. $sourceFile = MonographFileManager::getUploadedFilePath($fileName); // Instantiate and pre-populate a new monograph file object. $monographFile = MonographFileManager::_instantiateMonographFile($sourceFile, $monographId, $fileStage, $revisedFileId, $genreId, $assocId, $assocType); if (is_null($monographFile)) { return $nullVar; } // Retrieve and copy the file type of the uploaded file. $fileType = MonographFileManager::getUploadedFileType($fileName); assert($fileType !== false); $monographFile->setFileType($fileType); // Retrieve and copy the file name of the uploaded file. $originalFileName = MonographFileManager::getUploadedFileName($fileName); assert($originalFileName !== false); $monographFile->setOriginalFileName(MonographFileManager::truncateFileName($originalFileName)); // Set the uploader's user and user group id. $monographFile->setUploaderUserId($uploaderUserId); $monographFile->setUserGroupId($uploaderUserGroupId); // Copy the uploaded file to its final destination and // persist its meta-data to the database. $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */ return $submissionFileDao->insertObject($monographFile, $fileName, true); }