Last active
February 13, 2025 08:15
-
-
Save koertho/efa16d44ccded34d7f055dce52ff7020 to your computer and use it in GitHub Desktop.
Create a local copy with absolute Path from a Contao VirtualFileSystem file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace App\Controller; | |
| use Contao\CoreBundle\Filesystem\VirtualFilesystemInterface; | |
| use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |
| use Symfony\Component\Filesystem\Filesystem; | |
| class CreateLocalCopyWithVfsController | |
| { | |
| private readonly VirtualFilesystemInterface $filesStorage; | |
| private readonly ParameterBagInterface $parameterBag; | |
| public function __invoke(): void | |
| { | |
| $filePath = 'files/example.xlsx'; | |
| if (!$this->filesStorage->fileExists($filePath)) { | |
| return; | |
| } | |
| $tmpFilePath = $this->parameterBag->get('kernel.project_dir').'/var/tmp/'.uniqid().'.xlsx'; | |
| $fs = new Filesystem(); | |
| $fs->dumpFile( | |
| $tmpFilePath, | |
| $this->filesStorage->readStream($filePath) | |
| ); | |
| // Do something with the local file | |
| # ... | |
| // End Do something with the local file | |
| $fs->remove($tmpFilePath); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment