public function loadFromContainer(AssetContainer $assetContainer) { $stream = $assetContainer->getStream(); $this->readimagefile($stream); fclose($stream); $this->setDefaultQuality(); }
/** * Save an file passed from a form post into this object. * File names are filtered through {@link FileNameFilter}, see class documentation * on how to influence this behaviour. * * @param $tmpFile array Indexed array that PHP generated for every file it uploads. * @param $folderPath string Folder path relative to /assets * @return Boolean|string Either success or error-message. */ public function load($tmpFile, $folderPath = false) { if (!is_array($tmpFile)) { throw new InvalidArgumentException("Upload::load() Not passed an array. Most likely, the form hasn't got the right enctype"); } // Validate $this->clearErrors(); $valid = $this->validate($tmpFile); if (!$valid) { return false; } // Clean filename if (!$folderPath) { $folderPath = $this->config()->uploads_folder; } $nameFilter = FileNameFilter::create(); $file = $nameFilter->filter($tmpFile['name']); $filename = basename($file); if ($folderPath) { $filename = File::join_paths($folderPath, $filename); } // Validate filename $filename = $this->resolveExistingFile($filename); // Save file into backend $conflictResolution = $this->replaceFile ? AssetStore::CONFLICT_OVERWRITE : AssetStore::CONFLICT_RENAME; $this->file->setFromLocalFile($tmpFile['tmp_name'], $filename, null, null, $conflictResolution); // Save changes to underlying record (if it's a DataObject) if ($this->file instanceof DataObject) { $this->file->write(); } //to allow extensions to e.g. create a version after an upload $this->file->extend('onAfterUpload'); $this->extend('onAfterLoad', $this->file); return true; }
/** * Helper method to get local filesystem path for this file * * @param AssetContainer $asset */ public static function getLocalPath(AssetContainer $asset) { if ($asset instanceof Folder) { return self::base_path() . '/' . $asset->getFilename(); } if ($asset instanceof File) { $asset = $asset->File; } // Extract filesystem used to store this object /** @var AssetStoreTest_SpyStore $assetStore */ $assetStore = Injector::inst()->get('AssetStore'); $fileID = $assetStore->getFileID($asset->Filename, $asset->Hash, $asset->Variant); $filesystem = $assetStore->getProtectedFilesystem(); if (!$filesystem->has($fileID)) { $filesystem = $assetStore->getPublicFilesystem(); } /** @var Local $adapter */ $adapter = $filesystem->getAdapter(); return $adapter->applyPathPrefix($fileID); }
/** * * @param AssetContainer $file * @return string URL to thumbnail */ protected function getThumbnailURLForFile(AssetContainer $file) { if (!$file->exists()) { return null; } // Attempt to generate image at given size $width = $this->getPreviewMaxWidth(); $height = $this->getPreviewMaxHeight(); if ($file->hasMethod('ThumbnailURL')) { return $file->ThumbnailURL($width, $height); } if ($file->hasMethod('Thumbnail')) { return $file->Thumbnail($width, $height)->getURL(); } if ($file->hasMethod('Fit')) { return $file->Fit($width, $height)->getURL(); } // Check if unsized icon is available if ($file->hasMethod('getIcon')) { return $file->getIcon(); } }
public function loadFromContainer(AssetContainer $assetContainer) { // If we're working with image resampling, things could take a while. Bump up the time-limit increase_time_limit_to(300); $this->resetResource(); // Skip non-existant files if (!$assetContainer->exists()) { return; } // Skip if failed before $filename = $assetContainer->getFilename(); $hash = $assetContainer->getHash(); $variant = $assetContainer->getVariant(); if ($this->failedResample($filename, $hash, $variant)) { return; } // Mark as potentially failed prior to creation, resetting this on success $content = $assetContainer->getString(); $image = imagecreatefromstring($content); if ($image === false) { $this->markFailed($filename, $hash, $variant); return; } imagealphablending($image, false); imagesavealpha($image, true); // save alphablending setting (important) $this->setImageResource($image); }
/** * Helper method to get local filesystem path for this file * * @param AssetContainer $asset */ public static function getLocalPath(AssetContainer $asset) { if ($asset instanceof Folder) { return self::base_path() . '/' . $asset->getFilename(); } if ($asset instanceof File) { $asset = $asset->File; } if ($asset instanceof DBFile) { return BASE_PATH . $asset->getSourceURL(); } return BASE_PATH . $asset->getUrl(); }
/** * Assign this temporary file into the given destination * * @param array $tmpFile * @param string $filename * @param AssetContainer|AssetStore $container * @return array */ protected function storeTempFile($tmpFile, $filename, $container) { // Save file into backend $conflictResolution = $this->replaceFile ? AssetStore::CONFLICT_OVERWRITE : AssetStore::CONFLICT_RENAME; $config = array('conflict' => $conflictResolution, 'visibility' => $this->getDefaultVisibility()); return $container->setFromLocalFile($tmpFile['tmp_name'], $filename, null, null, $config); }
/** * Assign this temporary file into the given destination * * @param array $tmpFile * @param string $filename * @param AssetContainer|AssetStore $container * @return array */ protected function storeTempFile($tmpFile, $filename, $container) { // Save file into backend $conflictResolution = $this->replaceFile ? AssetStore::CONFLICT_OVERWRITE : AssetStore::CONFLICT_RENAME; return $container->setFromLocalFile($tmpFile['tmp_name'], $filename, null, null, $conflictResolution); }