/** * adds a resource to the gallery when the resource is already stored on disk, instead of * it coming from an upload as it usually happens. This method is better than * GalleryResources::addResource() when instead of dealing with uploaded files, the file * is already in disk and all that is left to do is to add it to the database. * * @param ownerId * @param albumId * @param description * @param fullFilePath The real path where the file is stored. This is expected to be * its final and permanent destination * @return It will return one of the following constants: * - GALLERY_ERROR_RESOURCE_TOO_BIG * - GALLERY_ERROR_RESOURCE_FORBIDDEN_EXTENSION * - GALLERY_ERROR_QUOTA_EXCEEDED * - GALLERY_ERROR_ADDING_RESOURCE * - GALLERY_ERROR_UPLOADS_NOT_ENABLED * or the identifier of the resource that was just added if the operation succeeded. */ function addResourceFromDisk($ownerId, $albumId, $description, $fullFilePath) { // check if quotas are enabled, and if this file would make us go // over the quota if (GalleryResourceQuotas::isBlogOverResourceQuota($ownerId, File::getSize($fullFilePath))) { return GALLERY_ERROR_QUOTA_EXCEEDED; } $fileName = basename($fullFilePath); $filePath = dirname($fullFilePath); // get the metadata $getId3 = new GetID3(); $metadata = $getId3->analyze($fullFilePath); // nifty helper method from the getid3 package getid3_lib::CopyTagsToComments($metadata); $resourceType = $this->_getResourceType($fullFilePath, $metadata); $info = $this->_filterMetadata($metadata, $resourceType); // set the flags $flags = 0; if ($resourceType == GALLERY_RESOURCE_IMAGE) { $flags = $flags | GALLERY_RESOURCE_PREVIEW_AVAILABLE; } // add the record to the database $resourceId = $this->addResourceToDatabase($ownerId, $albumId, $description, $flags, $resourceType, $filePath, $fileName, $metadata); if (!$resourceId) { return false; } // and finally move the file to the right place in disk // move the file to disk $storage = new GalleryResourceStorage(); $resFile = $storage->storeFile($resourceId, $ownerId, $fullFilePath, RESOURCE_STORAGE_STORE_MOVE); // if the file cannot be read, we will also remove the record from the // database so that we don't screw up $fileReadable = File::isReadable($resFile); if (!$resFile || $resFile < 0 || !$fileReadable) { // if something went wrong, we should not keep the record in the db $query = "DELETE FROM " . $this->getPrefix() . "gallery_resources\n WHERE id = {$resourceId}"; $this->Execute($query); return $resFile; } // and finally, we can generate the thumbnail only if the file is an image, of course :) if ($resourceType == GALLERY_RESOURCE_IMAGE) { $this->generateResourceThumbnail($resFile, $resourceId, $ownerId); } // return the id of the resource we just added return $resourceId; }