Download the PHP package hasanhawary/media-manager without Composer
On this page you can find all versions of the php package hasanhawary/media-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hasanhawary/media-manager
More information about hasanhawary/media-manager
Files in hasanhawary/media-manager
Package media-manager
Short Description Flexible Laravel media manager: accept media from UploadedFile, base64, URLs, or local paths and store on any filesystem disk.
License MIT
Homepage https://github.com/hasanhawary/media-manager
Informations about the package media-manager
Media Manager
Media Manager is a reusable Laravel package for storing files from uploaded files, base64 strings, remote URLs, raw content, and local paths. It supports disk selection, naming strategies, replacement flows, chunked uploads, URL generation, metadata, delete, and safe delete.
The package is self-contained and does not depend on a host app namespace such as App\....
Requirements
- PHP 8.1+
- Laravel 10, 11, 12, or 13
- Configured Laravel filesystem disks
Some low-level helpers such as PathNormalizer, FileNameGenerator, and RemoteMediaFetcher can be used in plain PHP. Storage, facades, UploadedFile, URL generation, metadata, and chunk uploads are Laravel filesystem features.
Installation
Laravel discovers the service provider and facade alias automatically:
Publish the optional config file:
Configuration
Published config: config/media-manager.php
disk => null means the package uses filesystems.default.
The package registers POST /media-manager/chunk-file by default. Change routes.prefix, routes.middleware, or set routes.enabled to false if you need to avoid route conflicts.
Quick Start
Fluent options:
If no path is passed to upload(), the package uses media-manager.path.
Supported Sources
| Source | Example |
|---|---|
| Uploaded file | $request->file('avatar') |
| Base64 data URI | data:image/png;base64,... |
| Plain base64 string | base64_encode($contents) |
| Remote URL | https://example.com/photo.jpg |
| Raw content | Hello world |
| Local path | storage_path('app/temp/logo.png') |
Remote URLs are validated before fetching. Local/private IP URLs are rejected by default to reduce SSRF risk.
Naming
| Strategy | Behavior |
|---|---|
uuid |
Generated UUID filename |
hash |
MD5 hash for uploaded files, UUID fallback for generated content |
timestamp |
Timestamp plus random suffix |
original |
Keep the original filename when available |
custom |
Use withName() string or closure |
Filenames are sanitized with basename() before storage.
Replacing Files
| Input value | Behavior |
|---|---|
null, '', or [] |
Keep the old path |
'delete' |
Delete the old file and return null |
| Same path | Keep the existing file |
| New source | Store the new file and delete the old file after success |
Chunk Uploads
Use the fluent API directly:
| Key | Required | Description |
|---|---|---|
file_name |
yes | Final filename with extension |
chunk_number |
yes | 1-based chunk number |
chunk_file |
yes | Illuminate\Http\UploadedFile chunk |
is_final |
no | Merge chunks when true |
user_id |
sometimes | Used to isolate chunk directories |
directory |
no | Final merged file directory |
If user_id is not provided, Laravel apps fall back to auth()->id(). Outside Laravel auth, user_id is required.
Chunks are stored under media-manager.chunks.directory, merged in numeric order, streamed into the final file, and then cleaned up.
Or use the default package route:
Multipart form fields:
| Field | Required | Description |
|---|---|---|
file_name |
yes | Final filename with extension |
chunk_number |
yes | 1-based chunk number |
chunk_file |
yes | Uploaded chunk file |
is_final |
no | Boolean-ish value such as 1, true, or 0 |
user_id |
sometimes | Required when no authenticated Laravel user exists |
directory |
no | Final merged file directory |
Successful non-final response:
Successful final response:
URLs
url(), temporaryUrl(), and signedUrl() return null for missing paths. Arrays of paths return an array when more than one path resolves.
Metadata
MediaMeta is JSON serializable.
File Operations
exists(), delete(), and safeDelete() normalize package-generated disk URLs back to disk paths. External URLs are ignored.
safeDelete() moves files to trash/ on the selected disk.
Exceptions
The package fails explicitly for invalid usage:
| Exception | Example |
|---|---|
NoHandlerDefinedException |
Calling store() before selecting a source |
UnsupportedTypeException |
Passing an unsupported source type |
InvalidArgumentException |
Invalid naming strategy, chunk data, empty disk name |
ApiHandler and ZipHandler are placeholders and throw UnsupportedTypeException.
Plain PHP Notes
These classes do not require a Laravel application container:
Storage-backed operations require Laravel filesystem components.
Testing
The package test suite is isolated from any host project.
License
MIT © Hasan Hawary
All versions of media-manager with dependencies
illuminate/config Version ^10.0 || ^11.0 || ^12.0 || ^13.0
illuminate/container Version ^10.0 || ^11.0 || ^12.0 || ^13.0
illuminate/filesystem Version ^10.0 || ^11.0 || ^12.0 || ^13.0
illuminate/http Version ^10.0 || ^11.0 || ^12.0 || ^13.0
illuminate/support Version ^10.0 || ^11.0 || ^12.0 || ^13.0
league/flysystem Version ^3.0
league/flysystem-local Version ^3.0