karelwintersky / arris.php-file-upload
A library to help with uploading files in PHP
0.2.1
2024-08-12 00:29 UTC
Requires
- php: >=7.4 | 8.*
- ext-exif: *
- ext-fileinfo: *
Requires (Dev)
- phpunit/phpunit: ^8
This package is auto-updated.
Last update: 2024-12-12 01:16:58 UTC
README
Uploader 🚀
Safe, simple and useful file upload class
Installing
composer require karelwintersky/arris.php-file-upload
Examples
Basic:
use Arris\Toolkit\FileUpload; if (isset($_FILES["file"])) { $upload = new FileUpload($_FILES["file"]); $upload->setAllowedExtensions(array("png", "jpg", "jpeg", "gif")); $upload->setMaxSize(5); // in MB $upload->setPath("upload/files"); $upload->setName("foo"); if (! $upload->upload()) { echo "Upload error: " . $upload->getError(); } else { echo "Upload successful!"; } }
Inline using:
use Arris\Toolkit\FileUpload; if (isset($_FILES["file"])) { $upload = (new FileUpload($_FILES["file"]))->setMaxSize(20)->setPath("upload/files")->encrypt_name(); if (! $upload->upload()) { echo "Upload error: " . $upload->getError(); } else { echo "Upload successful!"; } }
More examples in the "examples" directory.
Methods
Notes
exif
and fileinfo
extensions must be enabled.
Based on https://github.com/iamdual/uploader