/** * 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 $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, $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; } // Instantiate and pre-populate a new monograph file object. $monographFile = MonographFileManager::_instantiateMonographFile($monographId, $fileStage, $revisedFileId, $genreId, $assocId, $assocType); if (is_null($monographFile)) { return $nullVar; } // Retrieve file information from the uploaded file. assert(isset($_FILES[$fileName])); $monographFile->setFileType($_FILES[$fileName]['type']); $monographFile->setOriginalFileName(MonographFileManager::truncateFileName($_FILES[$fileName]['name'])); // Set the uploader's userGroupId // FIXME: Setting a temporary user group here until #6231 is fixed. // This is necessary so that we can already remove the user-group // attribute from the session. $monographFile->setUserGroupId(1); // Copy the uploaded file to its final destination and // persist its meta-data to the database. return MonographFileManager::_persistFile($fileName, $monographFile); }