codeguy/upload

This package is abandoned and no longer maintained. The author suggests using the league/flysystem package instead.

Handle file uploads with extensible validation and storage strategies

Package info

github.com/brandonsavage/Upload

Homepage

pkg:composer/codeguy/upload

Statistics

Installs: 1 116 921

Dependents: 38

Suggesters: 1

Stars: 1 672

Open Issues: 40

1.3.2 2013-07-07 17:01 UTC

Requires

  • php: >=5.3.0
  • ext-fileinfo: *

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 6a9e5e1fb58d65346d0e557db2d46fb25efd3e37

fileuploadvalidation

This package is not auto-updated.

Last update: 2024-05-05 11:41:52 UTC


README

👁 Build Status
👁 Latest Version
👁 Total Downloads

This component simplifies file validation and uploading.

Usage

Assume a file is uploaded with this HTML form:

<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:

<?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:

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

Require the package with composer:

php composer.phar require codeguy/upload

Author

Josh Lockhart

License

MIT Public License