Download the PHP package initphp/upload without Composer
On this page you can find all versions of the php package initphp/upload. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download initphp/upload
More information about initphp/upload
Files in initphp/upload
Package upload
Short Description Validate and store uploaded files on local disk, FTP/FTPS or Amazon S3 through a single adapter-based API.
License MIT
Informations about the package upload
InitPHP Upload
Validate and store uploaded files on local disk, FTP/FTPS or Amazon S3 through a single, adapter-based API.
Requirements
- PHP 8.0 or higher
ext-fileinfo(used to detect the real MIME type of a file)ext-ftp— only for the FTP adapteraws/aws-sdk-php— only for the S3 adapter
Installation
For S3 uploads, also install the AWS SDK:
Quick start
File::setPost('photos') reads $_FILES['photos'] and returns a normalized
File[], whether the field uploaded one file or many. to() validates the
file, stores it, and returns the stored File (with its public URL set) or
false if the underlying write failed. Any validation or transfer problem is
thrown as an UploadException.
Loading files
| Call | Returns | Purpose |
|---|---|---|
File::setPost(string $key) |
File[] |
Normalize $_FILES[$key] (single or multiple) into File objects. |
File::setPath(string $path) |
File |
Wrap an existing file already on disk. |
A file loaded with setPath() is copied to its destination (the source is
left in place); a real HTTP upload is moved with move_uploaded_file().
Adapters
All three adapters share the same API — only the credentials differ. The optional second constructor argument is the validation options, identical across adapters.
| Adapter | Credentials | Notes |
|---|---|---|
LocalAdapter |
dir, url |
Creates missing destination directories. |
FTPAdapter |
host, port, username, password, timeout, url, passive, ssl |
Binary mode, passive by default, optional FTPS. |
S3Adapter |
key, secret_key, region, bucket, ACL, version |
Requires aws/aws-sdk-php. |
The to($target) argument
$target means the same thing in every adapter: a destination path/key
prefix. to('avatars/2026') stores the file under that sub-path:
- Local →
<dir>/avatars/2026/<name> - FTP →
<remote>/avatars/2026/<name>(directories created as needed) - S3 → object key
avatars/2026/<name>in the configured bucket
Call to() with no argument to store the file at the destination root.
Validation options
Pass these as the second constructor argument of any adapter (an empty array or
0 means "no restriction"):
| Option | Type | Meaning |
|---|---|---|
allowed_extensions |
string[] |
Allowed file extensions, matched case-insensitively against the original file name. |
allowed_mime_types |
string[] |
Allowed MIME types, matched against the real type detected with finfo (not the client-supplied one). |
allowed_max_size |
int |
Maximum size in bytes. |
A file that violates any restriction — or whose upload errored — makes to()
throw an UploadException.
Renaming
Documentation
Full guides with examples live in docs/:
- Getting started
- The
Fileobject - Validation
- Local adapter
- FTP adapter
- S3 adapter
- Exceptions
Contributing
Bug reports and pull requests are welcome. CI runs PHP-CS-Fixer, PHPStan (max level) and PHPUnit across PHP 8.0–8.4; run the same bundle locally with:
Credits
License
Copyright © 2023 InitPHP — released under the MIT License.
All versions of upload with dependencies
ext-fileinfo Version *