Linux SRV-16 6.18.44-paas #1 SMP PREEMPT_DYNAMIC Thu Aug 13 10:08:12 UTC 2026 x86_64
/
srv
/
data
/
web
/
vhosts
/
716cf56cb2.url-de-test.ws
/
htdocs
/
src
/
Service
/
/srv/data/web/vhosts/716cf56cb2.url-de-test.ws/htdocs/src/Service/UploadImageService.php
<?php namespace App\Service; use App\Entity\Logement; use App\Entity\Product; use App\Entity\ProductImages; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\Exception\FileException; class UploadImageService { protected $em; public function __construct(EntityManagerInterface $em) { $this->em = $em; } public function upload($image, Logement $logement, string $imageDirectory) { $originalFilename = pathinfo($image->getClientOriginalName(), PATHINFO_FILENAME); $newFilename = $originalFilename . '-' . uniqid() . '.' . $image->guessExtension(); try { $image->move( $imageDirectory, $newFilename ); $logement->setImageName($newFilename); } catch (FileException $e) { return $e; } } public function deleteImages(array $productImages, string $productImagesDirectory) { $filesystem = new Filesystem(); foreach ($productImages as $image) { $filePath = $productImagesDirectory . '/' . $image->getName(); try { $filesystem->remove($filePath); } catch (FileException $e) { return $e; } $this->em->remove($image); } } }