Framework agnostic upload library

Installs: 231 178

Dependents: 13

Suggesters: 0

Stars: 201

Watchers: 14

Forks: 27

Open Issues: 1

2.1.1 2017-07-31 08:18 UTC


Source Code Latest Version Software License Build Status PHP 7 ready Coverage Status Quality Score Total Downloads

Framework agnostic upload handler library.


  1. Validates files agains 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.

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;
		$result->confirm(); // this will remove the .lock file
	} catch (\Exception $e) {
		// something wrong happened, we don't need the uploaded files anymore
		throw $e;
} else {
	// image was not moved to the container, where are error messages
	$messages = $result->getMessages();