public function __construct(FileSystem $localFileSystem, FileSystem $remoteFileSystem, CI $codeIgniter, \User $currentUser) { $this->localFileSystem = $localFileSystem; //gaufrette file system $this->remoteFileSystem = $remoteFileSystem; //gaufrette file system $this->basicPath = $this->localFileSystem->getAdapter()->getDirectory(); $codeIgniter->load->config('upload'); $this->tempPath = $codeIgniter->config->config['temp_upload_file_path']; $this->destPath = $codeIgniter->config->config['dest_upload_file_path']; $this->acceptFileTypes = $codeIgniter->config->config['default_file_types']; $this->maxFileSize = $codeIgniter->config->config['default_max_file_size']; $this->validator = new Validator($this->maxFileSize, $this->acceptFileTypes); $this->setUser($currentUser); }
/** * Upload a file. * * @param MediaInterface $media */ public function upload(MediaInterface $media) { // the file property can be empty if the field is not required if (null === $media->getFile()) { return; } $adapter = $this->filesystem->getAdapter(); if ($adapter instanceof AwsS3) { $adapter->setMetadata($media->getReference(), ['ContentType' => $media->getContentType()]); } $this->filesystem->write($media->getReference(), file_get_contents($media->getFile())); if (isset($media->temp)) { // delete the old image unlink($media->temp); // clear the temp image path $media->temp = null; } // clean up the file property as you won't need it anymore $media->setFile(null); }
/** * @return \Gaufrette\Adapter */ protected function getAdapter() { return $this->filesystem->getAdapter(); }