Stars: 224
Forks: 27
Pull Requests: 11
Issues: 27
Watchers: 14
Last Updated: 2023-08-06 19:40:11
Framework agnostic upload handler library
License: MIT License
Languages: PHP
Framework agnostic upload handler library.
UploadedFileInterface
objects and with Symfony's UploadedFile
s (see integrations).Used by Bolt CMS
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