https://github.com/lodev09/php-upload
A very simple yet useful helper class to handle PHP file uploads.
https://github.com/lodev09/php-upload
Last synced: 6 months ago
JSON representation
A very simple yet useful helper class to handle PHP file uploads.
- Host: GitHub
- URL: https://github.com/lodev09/php-upload
- Owner: lodev09
- License: mit
- Created: 2014-06-13T21:13:48.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2021-03-10T22:50:50.000Z (over 5 years ago)
- Last Synced: 2025-08-31T04:41:50.951Z (11 months ago)
- Language: PHP
- Homepage: https://packagist.org/packages/lodev09/php-upload
- Size: 23.4 KB
- Stars: 2
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PHP FileUpload Class
============================
A very simple yet useful helper class to handle PHP file uploads.
## Features
- Supports Multiple file uploads
- Supports Exif for images
- Built-in and Custom validations
- Simple implementation
- or you can ask for more ...
## Installation
```term
$ composer require lodev09/php-upload
```
## Usage
### HTML
```html
```
### PHP (server side)
```php
use \Upload\Upload;
if (isset($_FILES['files'])) {
$validations = array(
'category' => array('document', 'image', 'video'), // validate only those files within this list
'size' => 20 // maximum of 20mb
);
// create new instance
$upload = new Upload($_FILES['files'], $validations);
// for each file
foreach ($upload->files as $file) {
if ($file->validate()) {
// do your thing on this file ...
// ...
// say we don't allow audio files
if ($file->is('audio')) $error = 'Audio not allowed';
else {
// then get base64 encoded string to do something else ...
$filedata = $file->get_base64();
// or get the GPS info ...
$gps = $file->get_exif_gps();
// then we move it to 'path/to/my/uploads'
$result = $file->put('path/to/my/uploads');
$error = $result ? '' : 'Error moving file';
}
} else {
// oopps!
$error = $file->get_error();
}
echo $file->name.' - '.($error ? ' [FAILED] '.$error : ' Succeeded!');
echo '
';
}
}
?>
```
## Feedback
All bugs, feature requests, pull requests, feedback, etc., are welcome. Visit my site at [www.lodev09.com](http://www.lodev09.com "www.lodev09.com") or email me at [lodev09@gmail.com](mailto:lodev09@gmail.com)
## Credits
© 2018 - Coded by Jovanni Lo / [@lodev09](http://twitter.com/lodev09)
## License
Released under the [MIT License](http://opensource.org/licenses/MIT).
See [LICENSE](LICENSE) file.