Symfony bundle that standardize the way of handling data file associated with an entity
The bundle is not yet on packagist make sure to add the following to your composer.json file:
{
"url": "https://github.com/2lenet/FileBundle",
"type": "git"
}
Install with composer:
composer require 2lenet/file-bundle
in your controller or service juste use the fileManager to get the db and absolute path to use to store your data.
$fileSpec = $this->fileManager->getLocalFilename(
ENTITY::PDFSTORAGENAME,
$object,
"pdf"
);
The function return a FileSpec object with two attribute
Path are build this way ( $projectDir / data / $storeName / Y / M / D / $objet->getId() . $ext ) if the folder does not exist it is created with the right right. Y/M/D is the year, month and day from the $object->getDateForFilename() if it exist, instead it use the today date.
file_put_contents($fileSpec->absPath,$youdata);
$object->setLocalPdf($fileSpec->dbPath);
How can I help you explore Laravel packages today?