Download the PHP package ez-php/storage without Composer
On this page you can find all versions of the php package ez-php/storage. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ez-php/storage
More information about ez-php/storage
Files in ez-php/storage
Package storage
Short Description File storage abstraction for the ez-php framework — local filesystem and S3-compatible drivers
License MIT
Homepage https://github.com/ez-php/storage
Informations about the package storage
ez-php/storage
File storage abstraction for the ez-php framework.
Provides a unified interface (put, get, delete, exists, url) over pluggable drivers. Ships with a LocalDriver (filesystem), an S3Driver (AWS S3 and S3-compatible APIs via cURL + AWS Signature V4), and a GcsDriver (Google Cloud Storage via cURL + Bearer access token). Integrates with UploadedFile from ez-php/http.
Installation
Configuration
Add config/storage.php to your application:
Register the provider in provider/modules.php:
Usage
Via static façade
Storing an uploaded file
Via dependency injection
Serving files over HTTP
StorageResponse turns a stored file into a response — with Range support so browsers can seek in audio/video and resume downloads:
| Request | Response |
|---|---|
no Range |
200, Content-Length, Accept-Ranges: bytes |
Range: bytes=2-5 / bytes=15- / bytes=-4 |
206 + Content-Range: bytes 2-5/20 |
unsatisfiable (bytes=100- on a 20-byte file) |
416 + Content-Range: bytes */20 |
| several ranges, another unit, malformed | 200, the whole file |
| unknown path | 404 |
Range needs a seekable stream (local files, in-memory); for a non-seekable remote stream the whole file is streamed without Content-Length. If-Range is not evaluated.
Let the web server send the file (PHP only checks access):
Expiring links for the LocalDriver (the S3 driver's url() is already presigned):
The signature is HMAC-SHA256 over the path and the expiry, compared in constant time; changing either invalidates it. A link is valid until it expires (no single-use tracking).
Drivers
LocalDriver
Stores files under a configurable root directory. Creates nested directories automatically.
S3Driver
Uploads and retrieves objects using cURL with AWS Signature Version 4. Works with AWS S3 and any S3-compatible service (MinIO, Cloudflare R2, DigitalOcean Spaces).
url()returns a presigned GET URL (valid forurl_expiryseconds)- If a custom
url(CDN) is configured,url()returns{url}/{path}instead - Custom
endpointoverrides the default{bucket}.s3.{region}.amazonaws.comhost; an explicithttp://scheme is kept (a local MinIO/LocalStack without TLS), any other endpoint is reached over HTTPS putStream()uploads streams larger thanmultipart_part_size(default 8 MiB) with S3 multipart upload, one part in memory at a time; failed uploads are aborted. Parts must be ≥ 5 MiB except the last (S3 rule).
GcsDriver
Uploads and retrieves objects using cURL against the Google Cloud Storage JSON API,
authenticated with a Bearer access token you supply (e.g. from
gcloud auth print-access-token, or a workload-identity/metadata-server token in
production). The driver never mints or refreshes tokens itself.
url()returns a directhttps://storage.googleapis.com/{bucket}/{path}URL by default.- With a service-account client email and private key,
url()returns an expiring V4 signed URL (GOOG4-RSA-SHA256,urlExpiryseconds, max 7 days);signedUrl($path, $ttl)picks the lifetime per call. The key only signs URLs (ext-openssl) — requests still use the Bearer token, and no OAuth2 tokens are minted. - If a custom
url(CDN) is configured,url()returns{url}/{path}instead. endpoint(storage.gcs.endpoint/GCS_ENDPOINT) replaceshttps://storage.googleapis.comas the API base — e.g.http://localhost:4443for a local fake-gcs-server. Public object URLs use it too; V4 signed URLs always target Google.
InMemoryDriver (tests only)
Keeps file contents in a PHP array — no filesystem, no network. Use it to test code
that depends on StorageInterface without writing real files.
Set STORAGE_DRIVER=memory to use it via the service provider.
- Rejects
..path segments exactly likeLocalDriver, so a traversal bug cannot pass against the double and then fail against the real driver. - Supports the full interface, streams included (
getStream()/putStream()usephp://memory). - Not for production. Nothing is persisted or shared between processes.
Running Tests
S3 integration tests are skipped unless AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_BUCKET are set in the environment. GCS integration tests are likewise skipped unless GCS_BUCKET and GCS_ACCESS_TOKEN are set.
All versions of storage with dependencies
ext-curl Version *
ez-php/contracts Version ^2.7.0
ez-php/http Version ^2.7.0