Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brandonsavage/Upload
File uploads with validation and storage strategies
https://github.com/brandonsavage/Upload
Last synced: about 1 month ago
JSON representation
File uploads with validation and storage strategies
- Host: GitHub
- URL: https://github.com/brandonsavage/Upload
- Owner: brandonsavage
- License: mit
- Archived: true
- Created: 2012-09-10T12:34:41.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2023-11-12T03:17:29.000Z (about 1 year ago)
- Last Synced: 2024-10-30T04:54:26.577Z (about 1 month ago)
- Language: PHP
- Homepage:
- Size: 86.9 KB
- Stars: 1,667
- Watchers: 85
- Forks: 314
- Open Issues: 39
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-php - Upload - A library for handling file uploads and validation. (Table of Contents / Filtering and Validation)
- awesome-php-cn - Upload - 一个库来处理文件上传和验证. (目录 / 过滤和验证 Filtering and Validation)
- awesome-projects - Upload - A library for handling file uploads and validation. (PHP / Filtering and Validation)
- awesome-php - Upload - A library for handling file uploads and validation. (Table of Contents / Filtering, Sanitizing and Validation)
README
# Upload
[![Build Status](https://img.shields.io/travis/brandonsavage/Upload.svg?style=flat-square)](https://travis-ci.org/brandonsavage/Upload)
[![Latest Version](https://img.shields.io/github/release/brandonsavage/Upload.svg?style=flat-square)](https://github.com/brandonsavage/Upload/releases)
[![Total Downloads](https://img.shields.io/packagist/dt/codeguy/upload.svg?style=flat-square)](https://packagist.org/packages/codeguy/upload)This component simplifies file validation and uploading.
## Usage
Assume a file is uploaded with this HTML form:
```html
```
When the HTML form is submitted, the server-side PHP code can validate and upload the file like this:
```php
setName($new_filename);// Validate file upload
// MimeType List => http://www.iana.org/assignments/media-types/media-types.xhtml
$file->addValidations(array(
// Ensure file is of type "image/png"
new \Upload\Validation\Mimetype('image/png'),//You can also add multi mimetype validation
//new \Upload\Validation\Mimetype(array('image/png', 'image/gif'))// Ensure file is no larger than 5M (use "B", "K", M", or "G")
new \Upload\Validation\Size('5M')
));// Access data about the file that has been uploaded
$data = array(
'name' => $file->getNameWithExtension(),
'extension' => $file->getExtension(),
'mime' => $file->getMimetype(),
'size' => $file->getSize(),
'md5' => $file->getMd5(),
'dimensions' => $file->getDimensions()
);// Try to upload file
try {
// Success!
$file->upload();
} catch (\Exception $e) {
// Fail!
$errors = $file->getErrors();
}
```## How to Install
Install composer in your project:
```
curl -s https://getcomposer.org/installer | php
```Require the package with composer:
```
php composer.phar require codeguy/upload
```## Author
[Josh Lockhart](https://github.com/codeguy)
## License
MIT Public License