Skip to content

Instantly share code, notes, and snippets.

@koertho
Last active February 13, 2025 08:15
Show Gist options
  • Select an option

  • Save koertho/efa16d44ccded34d7f055dce52ff7020 to your computer and use it in GitHub Desktop.

Select an option

Save koertho/efa16d44ccded34d7f055dce52ff7020 to your computer and use it in GitHub Desktop.
Create a local copy with absolute Path from a Contao VirtualFileSystem file.
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