Loading module/Information/src/Information/Controller/FichierController.php +5 −7 Original line number Diff line number Diff line Loading @@ -33,11 +33,11 @@ class FichierController extends AbstractActionController if ($request->isPost()) { $file = $request->getFiles()->toArray(); if ($file['chemin'] !== null) { $logoDir = $this->fileService->computeDirectoryPathForInformation(); $this->fileService->createWritableDirectory($logoDir); $pathDir = $this->fileService->computeDirectoryPathForInformation(); $this->fileService->createWritableDirectory($pathDir); $uploadPath = $file['chemin']['tmp_name']; $truePath = implode("/", [$logoDir, $file['chemin']['name']]); $truePath = implode("/", [$pathDir, $file['chemin']['name']]); var_dump($uploadPath . " -> ".$truePath); $ok = rename($uploadPath, $truePath); if (! $ok) { Loading Loading @@ -68,8 +68,7 @@ class FichierController extends AbstractActionController $fichier = $this->getInformationFichierService()->getInformationFichier($id); $this->getInformationFichierService()->delete($fichier); $logoDir = $this->fileService->computeDirectoryPathForInformation(); $filePath = implode("/", [$logoDir,$fichier->getNom()]); $filePath = $this->getInformationFichierService()->computeFilePath($fichier); $success = unlink($filePath); if (!$success) throw new RuntimeException("Un problème s'est produit lors de l'effacement sur le disque du fichier ".$filePath); Loading @@ -85,8 +84,7 @@ class FichierController extends AbstractActionController $id = $this->params()->fromRoute('id'); $fichier = $this->getInformationFichierService()->getInformationFichier($id); $logoDir = $this->fileService->computeDirectoryPathForInformation(); $filePath = implode("/", [$logoDir,$fichier->getNom()]); $filePath = $filePath = $this->getInformationFichierService()->computeFilePath($fichier); $contenuFichier = file_get_contents($filePath); Loading module/Information/src/Information/Service/InformationFichierService.php +13 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Information\Service; use Application\Service\File\FileServiceAwareTrait; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\OptimisticLockException; use Information\Entity\Db\InformationFichier; Loading @@ -10,6 +11,7 @@ use UnicaenApp\Service\EntityManagerAwareTrait; class InformationFichierService { use EntityManagerAwareTrait; use FileServiceAwareTrait; /** * @var InformationFichier $fichier Loading Loading @@ -83,4 +85,15 @@ class InformationFichierService { } return $result; } /** * @param InformationFichier $fichier * @return string */ public function computeFilePath($fichier) { $pathDir = $this->fileService->computeDirectoryPathForInformation(); $filePath = implode("/", [$pathDir, $fichier->getNom()]); return $filePath; } } No newline at end of file module/Information/src/Information/Service/InformationFichierServiceFactory.php +4 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Information\Service; use Application\Service\File\FileService; use Doctrine\ORM\EntityManager; use Zend\ServiceManager\ServiceLocatorInterface as ContainerInterface; Loading @@ -14,11 +15,14 @@ class InformationFichierServiceFactory { { /** * @var EntityManager $entityManager * @var FileService $fileService */ $entityManager = $container->get('doctrine.entitymanager.orm_default'); $fileService = $container->get(FileService::class); $service = new InformationFichierService(); $service->setEntityManager($entityManager); $service->setFileService($fileService); return $service; } Loading Loading
module/Information/src/Information/Controller/FichierController.php +5 −7 Original line number Diff line number Diff line Loading @@ -33,11 +33,11 @@ class FichierController extends AbstractActionController if ($request->isPost()) { $file = $request->getFiles()->toArray(); if ($file['chemin'] !== null) { $logoDir = $this->fileService->computeDirectoryPathForInformation(); $this->fileService->createWritableDirectory($logoDir); $pathDir = $this->fileService->computeDirectoryPathForInformation(); $this->fileService->createWritableDirectory($pathDir); $uploadPath = $file['chemin']['tmp_name']; $truePath = implode("/", [$logoDir, $file['chemin']['name']]); $truePath = implode("/", [$pathDir, $file['chemin']['name']]); var_dump($uploadPath . " -> ".$truePath); $ok = rename($uploadPath, $truePath); if (! $ok) { Loading Loading @@ -68,8 +68,7 @@ class FichierController extends AbstractActionController $fichier = $this->getInformationFichierService()->getInformationFichier($id); $this->getInformationFichierService()->delete($fichier); $logoDir = $this->fileService->computeDirectoryPathForInformation(); $filePath = implode("/", [$logoDir,$fichier->getNom()]); $filePath = $this->getInformationFichierService()->computeFilePath($fichier); $success = unlink($filePath); if (!$success) throw new RuntimeException("Un problème s'est produit lors de l'effacement sur le disque du fichier ".$filePath); Loading @@ -85,8 +84,7 @@ class FichierController extends AbstractActionController $id = $this->params()->fromRoute('id'); $fichier = $this->getInformationFichierService()->getInformationFichier($id); $logoDir = $this->fileService->computeDirectoryPathForInformation(); $filePath = implode("/", [$logoDir,$fichier->getNom()]); $filePath = $filePath = $this->getInformationFichierService()->computeFilePath($fichier); $contenuFichier = file_get_contents($filePath); Loading
module/Information/src/Information/Service/InformationFichierService.php +13 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Information\Service; use Application\Service\File\FileServiceAwareTrait; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\OptimisticLockException; use Information\Entity\Db\InformationFichier; Loading @@ -10,6 +11,7 @@ use UnicaenApp\Service\EntityManagerAwareTrait; class InformationFichierService { use EntityManagerAwareTrait; use FileServiceAwareTrait; /** * @var InformationFichier $fichier Loading Loading @@ -83,4 +85,15 @@ class InformationFichierService { } return $result; } /** * @param InformationFichier $fichier * @return string */ public function computeFilePath($fichier) { $pathDir = $this->fileService->computeDirectoryPathForInformation(); $filePath = implode("/", [$pathDir, $fichier->getNom()]); return $filePath; } } No newline at end of file
module/Information/src/Information/Service/InformationFichierServiceFactory.php +4 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Information\Service; use Application\Service\File\FileService; use Doctrine\ORM\EntityManager; use Zend\ServiceManager\ServiceLocatorInterface as ContainerInterface; Loading @@ -14,11 +15,14 @@ class InformationFichierServiceFactory { { /** * @var EntityManager $entityManager * @var FileService $fileService */ $entityManager = $container->get('doctrine.entitymanager.orm_default'); $fileService = $container->get(FileService::class); $service = new InformationFichierService(); $service->setEntityManager($entityManager); $service->setFileService($fileService); return $service; } Loading