siriusphp/upload

Framework agnostic upload library

Maintainers

👁 adrianmiu

Package info

github.com/siriusphp/upload

pkg:composer/siriusphp/upload

Statistics

Installs: 588 581

Dependents: 12

Suggesters: 0

Stars: 223

Open Issues: 0

4.0.0 2023-11-19 17:38 UTC

Requires

Suggests

  • knplabs/gaufrette: Alternative filesystem abstraction library for upload destinations
  • league/flysystem: To upload to different destinations, not just to the local file system

Provides

None

Conflicts

None

Replaces

None

MIT b3c2bb40a90641421c7e12be00f50eaf62942b91

  • Adrian Miu <adrian.woop@adrianmiu.ro>

filesecurityformuploadvalidationfile uploadpsr-7

This package is auto-updated.

Last update: 2026-06-11 18:19:16 UTC


README

👁 Source Code
👁 Latest Version
👁 Software License
👁 Build Status
👁 Coverage Status
👁 Quality Score
👁 Total Downloads

Framework agnostic upload handler library.

Features

  1. Validates files against usual rules: extension, file size, image size (wdith, height, ratio). It uses Sirius Validation for this purpose.
  2. Moves valid uploaded files into containers. Containers are usually local folders but you can implement your own or use other filesystem abstractions like Gaufrette or Flysystem.
  3. Works with PSR7 UploadedFileInterface objects and with Symfony's UploadedFiles (see integrations).

Used by Bolt CMS

Elevator pitch

use Sirius\Upload\Handler as UploadHandler;
$uploadHandler = new UploadHandler('/path/to/local_folder');

// validation rules
$uploadHandler->addRule('extension', ['allowed' => ['jpg', 'jpeg', 'png']], '{label} should be a valid image (jpg, jpeg, png)', 'Profile picture');
$uploadHandler->addRule('size', ['max' => '20M'], '{label} should have less than {max}', 'Profile picture');

$result = $uploadHandler->process($_FILES['picture']); // ex: subdirectory/my_headshot.png

if ($result->isValid()) {
	// do something with the image like attaching it to a model etc
	try {
		$profile->picture = $result->name;
		$profile->save();
		$result->confirm(); // this will remove the .lock file
	} catch (\Exception $e) {
		// something wrong happened, we don't need the uploaded files anymore
		$result->clear();
		throw $e;
	}
} else {
	// image was not moved to the container, where are error messages
	$messages = $result->getMessages();
}

Links