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); }
/** * Create a unique filename based on the original filename. * * This checks the filesystem for other files that start with the original base name. * It does not check the database to avoid overwriting files that are not persisted * to the database for whatever reason. * * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file * * @return string */ public function createUniqueFileName($file) { $ext = '.' . $file->guessExtension(); if ($ext === '.txt' && null !== ($clientExt = $file->guessClientExtension())) { $ext = '.' . $clientExt; } $basename = trim(str_replace('.' . $file->getClientOriginalExtension(), '', $file->getClientOriginalName())); $basename = str_replace(' ', '-', $basename); $basename = strtolower($basename); $existing = $this->filesystem->listKeys($basename); if (isset($existing['keys'])) { $existing = $existing['keys']; } if (count($existing)) { $ids = [1]; foreach ($existing as $neighbor) { $neighbor = str_replace($ext, '', $neighbor); if (preg_match('/(\\d+)$/', $neighbor, $matches)) { $ids[] = intval($matches[1]); } } rsort($ids); $id = reset($ids); ++$id; $basename = $basename . '-' . $id; } return $basename . $ext; }
/** * Deletes a record * * @param Number $id ID of record * * @return Response $response Result of the action */ public function deleteAction($id) { if ($this->gaufrette->has($id)) { $this->gaufrette->delete($id); } return parent::deleteAction($id); }
/** * Reads the content from the file * * @param string $key Key of the file * * @throws \Gaufrette\Exception\FileNotFound when file does not exist * @throws \RuntimeException when cannot read file * * @return string */ public function read($key) { return $this->fileSystem->read($key); }
/** * @return \Gaufrette\Adapter */ protected function getAdapter() { return $this->filesystem->getAdapter(); }