private function generateParametersArray(File $file) { $types = ['width', 'height', 'crop', 'gravity']; $return = []; foreach ($types as $metaKey) { if ($file->hasMeta($metaKey)) { $return[$metaKey] = $file->getMeta($metaKey); } } return $return; }
public function __construct($key, $file, $uploaderPath, $meta = [], $store = true) { parent::__construct($file); $this->key = $key; $this->store = $store; $this->meta = $meta; $this->uploaderPath = $uploaderPath; }
public function store(File $file, $path) { $fullPath = sprintf('%s/%s', $this->config['root_folder'], $path); if (!is_dir($fullPath)) { mkdir($fullPath, 0755, true); } $filePath = sprintf('%s/%s', $fullPath, $file->getFilename()); rename($file->getPathname(), $filePath); $file->setUrl($this->resolveUrl($file)); $file->setName(sprintf('%s/%s', $file->getUploaderPath(), $file->getFilename())); foreach ($file->getEditions() as $edition) { if ($edition->store() === true) { $from_upload_path = sprintf('%s/%s', $edition->getUploaderPath(), $edition->getFilename()); $to_upload_path = sprintf('%s/%s', $path, $edition->getFilename()); $this->move($from_upload_path, $to_upload_path); $edition->setUrl($this->resolveUrl($edition)); } } return $file; }
public function store(File $file, $path) { $response = $this->upload($file->getPathname(), $path); // Resolves to upload path, e.g. users/1/adsadasd.jpg $file->setName(sprintf('%s.%s', $response['public_id'], $file->getExtension())); $file->setUrl($response['secure_url']); // Set the type here, otherwise getType will be called after the temp // file has been deleted. $file->setType($response['resource_type'] === 'image' ? 'image' : 'file'); if (!isset($this->config['editions']) || !is_array($this->config['editions'])) { $this->config['editions'] = []; } $thumbnailsConfig = $this->uploaderConfig->get('thumbnails'); $this->config['editions']['thumbnail'] = ['crop' => $thumbnailsConfig['crop'], 'height' => $thumbnailsConfig['height'], 'width' => $thumbnailsConfig['width']]; foreach ($this->config['editions'] as $key => $edition) { $edition = new Edition($key, null, $path, ['type' => 'image', 'height' => $edition['height'], 'width' => $edition['width'], 'crop' => $edition['crop'], 'cloudinary_response' => $response], false); $url = $this->resolveUrl($edition); $edition->setUrl($url); $file->addEdition($edition); } return $file; }
public function generateName(File $file) { return sprintf('%s.%s', uniqid(), $file->getExtension()); }
public function generateName(File $file) { return sprintf('%s_%s.%s', time(), mt_rand(1, 100000), $file->getExtension()); }
public function generateName(File $file) { return $file->getFilename(); }