2017 © Pedro Peláez
 

library upload

Handle file uploads with extensible validation and storage strategies

image

codeguy/upload

Handle file uploads with extensible validation and storage strategies

  • Thursday, March 3, 2016
  • by brandonsavage
  • Repository
  • 92 Watchers
  • 1515 Stars
  • 247,840 Installations
  • PHP
  • 43 Dependents
  • 2 Suggesters
  • 296 Forks
  • 34 Open issues
  • 9 Versions
  • 6 % Grown

The README.md

Upload

Build Status Latest Version Total Downloads, (*1)

This component simplifies file validation and uploading., (*2)

Usage

Assume a file is uploaded with this HTML form:, (*3)

<form method="POST" enctype="multipart/form-data">
    <input type="file" name="foo" value=""/>
    <input type="submit" value="Upload File"/>
</form>

When the HTML form is submitted, the server-side PHP code can validate and upload the file like this:, (*4)

<?php
$storage = new \Upload\Storage\FileSystem('/path/to/directory');
$file = new \Upload\File('foo', $storage);

// Optionally you can rename the file on upload
$new_filename = uniqid();
$file->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:, (*5)

curl -s https://getcomposer.org/installer | php

Require the package with composer:, (*6)

php composer.phar require codeguy/upload

Author

Josh Lockhart, (*7)

License

MIT Public License, (*8)

The Versions

03/03 2016

dev-master

9999999-dev http://github.com/codeguy/Upload

Handle file uploads with extensible validation and storage strategies

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-fileinfo *

 

The Development Requires

file validation upload

08/08 2014

dev-cleanup

dev-cleanup http://github.com/codeguy/Upload

Handle file uploads with extensible validation and storage strategies

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-fileinfo *

 

The Development Requires

file validation upload

07/07 2013

1.3.2

1.3.2.0 http://github.com/codeguy/Upload

Handle file uploads with extensible validation and storage strategies

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-fileinfo *

 

The Development Requires

file validation upload

15/04 2013

dev-develop

dev-develop http://github.com/codeguy/Upload

Handle file uploads with extensible validation and storage strategies

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • mikey179/vfsstream *

 

The Development Requires

file validation upload

06/11 2012

1.3.1

1.3.1.0 http://github.com/codeguy/Upload

Handle file uploads with extensible validation and storage strategies

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

file validation upload

11/09 2012

1.3.0

1.3.0.0 http://github.com/codeguy/Upload

Handle file uploads with extensible validation and storage strategies

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

file validation upload

10/09 2012

1.2.0

1.2.0.0 http://github.com/codeguy/Upload

Handle file uploads with extensible validation and storage strategies

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

file validation upload

10/09 2012

1.1.0

1.1.0.0 http://github.com/codeguy/Upload

Handle file uploads with extensible validation and storage strategies

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

file validation upload

10/09 2012

1.0.0

1.0.0.0 http://github.com/codeguy/Upload

Handle file uploads with extensible validation and storage strategies

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

file validation upload