- How do I install iiirxs/image-upload-bundle with Composer?
- Run composer require iiirxs/image-upload-bundle in your project root. In Symfony, enable the bundle in config/bundles.php and set your storage path and validation options in the package configuration. In Laravel there is no auto-discovered service provider, so you register the classes you need in a service provider or resolve them manually.
- Does iiirxs/image-upload-bundle work with Laravel applications?
- The package is distributed as a Symfony bundle, but its upload, validation, and storage logic is plain PHP, so you can call it from Laravel controllers and form requests. You will need to bind the upload service in a service provider and pass Laravel configuration values yourself. If you want native facades, config publishing, and Blade helpers, a Laravel-first package may fit better.
- How do I configure the upload directory for stored images?
- Storage location is configurable, so point it at a directory outside the public webroot and serve files through a controller or a symlink. Make sure the directory exists and the PHP process has write permissions. In Laravel, read the path from config/filesystems.php or an environment variable and pass it to the upload service.
- What validation does the bundle perform on uploaded images?
- It validates MIME type, file extension, and file size out of the box before the file is stored. That blocks many spoofed or oversized uploads, but it does not check image dimensions, re-encode pixels, or scan for malware. Add those checks in your application layer if you accept untrusted public uploads.
- How does the bundle generate safe unique filenames?
- It generates safe filenames and avoids collisions automatically, so two users uploading photo.jpg do not overwrite each other. Naming strategies are configurable if you prefer random hashes, slugs, or date-based paths. Keep the original extension server-side and never trust client-supplied names for paths.
- Can I use this bundle to upload PDFs or other non-image files?
- It is built for images and its validation defaults target image MIME types and extensions. If you need arbitrary documents, video, or archives, a general file-upload or media-library package is a better fit. You could extend validation, but you would be working against the package's intent.
- How do I test image uploads with this bundle?
- Use a temporary storage directory in tests and a fake uploaded file object, such as Symfony's UploadedFile or Laravel's UploadedFile::fake(). Assert that the service returns the expected stored path and that the file exists, then clean up the temp directory. Because the storage path is configurable, you can isolate tests without touching real uploads.
- What should I check before using it in production?
- Verify directory permissions, keep uploads outside the document root, and enforce request size limits in PHP and your web server. Generate unpredictable filenames, serve images with correct content types, and consider re-encoding images to strip metadata. For scale, add an adapter that writes to object storage or a CDN.
- Can I add custom image processing or a different storage backend?
- Yes, the design is extensible for custom processing and storage adapters, so you can plug in resizing, watermarking, or S3 uploads. Implement your adapter, wire it into the upload service, and keep the validation step in front of it. Confirm the extension points in the current source before committing to a custom pipeline.
- What are the alternatives to iiirxs/image-upload-bundle for Laravel and Symfony?
- In Laravel, the built-in Storage facade and UploadedFile store methods cover simple uploads, while Spatie Media Library and Intervention Image add media collections and processing. In Symfony, VichUploaderBundle is the common choice. This bundle is a lightweight option when you only need validated image storage with safe filenames.