antonio150/uploadimagebundle

There is no license information available for the latest version (dev-main) of this package.

Un bundle Symfony pour l'upload d'images

dev-main 2025-04-22 18:25 UTC

This package is auto-updated.

Last update: 2025-06-22 18:55:06 UTC


README

Introduction

The UploadImageBundle is a Symfony bundle that provides an easy way to upload and manage files in your Symfony application.

Installation

To install the bundle, use Composer:

composer require antonio150/uploadimagebundle:dev-main

Configuration

Run commande to choose path to store file

symfony console upload-image-bundle:install

Add the bundle to your config/bundles.php file if missing:

return [
    // ...
    UploadImageBundle\UploadImageBundle::class => ['all' => true],
];

Usage

To use the bundle

Edit your controller :

     namespace App\Controller;
     use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
     use Symfony\Component\HttpFoundation\Request;
     use Symfony\Component\HttpFoundation\Response;
     use Symfony\Component\Routing\Attribute\Route;
     use UploadImageBundle\Service\FileUploader;

     final class UploadimageController extends AbstractController{

         
         #[Route('/uploadimage', name: 'app_uploadimage')]
         public function upload(Request $request, FileUploader $fileUploader): Response
         {
             $file = $request->files->get('file'); // Récupérer le fichier depuis la requête
             if (!$file) {
                 return $this->json(['error' => 'Aucun fichier envoyé'], Response::HTTP_BAD_REQUEST);
             }

             try {
                 $result = $fileUploader->upload($file); // To get path and file name
                 return $this->json($result);
             } catch (\Exception $e) {
                 return $this->json(['error' => $e->getMessage()], Response::HTTP_BAD_REQUEST);
             }
         }

     }

Contact

Portfolio : antonio navira