2017 © Pedro Peláez
 

library file

File component of AttwFramework

image

attwframework/file

File component of AttwFramework

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

File

Total Downloads Latest Unstable Version License, (*1)

File component of AttwFramework., (*2)

Composer

Download

{
    "require": {
        "attwframework/file": "dev-master"
    }
}

How to use

A file is represented with the class Attw\File\File., (*3)

Pass in it constructor an array with file datils (global variable $_FILES)., (*4)

use Attw\File\File;

//...

$file = new File($_FILES['file']);

All components of namespace Attw\File use the file class., (*5)

Upload

To upload a file, use the class Attw\File\Uploader\Uploader., (*6)

The method used to upload a file is Attw\File\Uploader\Uploader::upload($file, $directory)., (*7)

use Attw\File\File;
use Attw\File\Uploader\Uploader;

//...

$file = new File($_FILES['file']);
$uploader = new Uploader();
if($uploader->upload($file, 'public/files')){
    //success
}

File validators

Also have the possibility of validate the files., (*8)

The validators are: * Attw\File\Validator\MaxSize: Don't allow that a file have more than specified maximum size * Constructor: Attw\File\Validator\MaxSize::__construct($maxSize). $maxSize must be an integer and indicated in MB * Attw\File\Validator\MinSize: Don't allow that a file have more than specified minimum size * Constructor: Attw\File\Validator\MinSize::__construct($minSize). $minSize must be an integer and indicated in MB * Attw\File\Validator\Extension: Don't allow that a file have a invalid extension * Constructor: Attw\File\Validator\Extenction::__construct($extensions). $extensions must be an array with the allowed extensions. * Attw\File\Validator\Type: Don't allow that a file have a invalid type * Constructor: Attw\File\Validator\Type::__construct($types). $types must be an array with the allowed types., (*9)

use Attw\File\File;
use Attw\File\Validator\Extension;

//...

$file = new File($_FILES['file']);
$validator = new Extension([ 'jpg', 'png', 'gif' ]);

if($validator->validate($file)){
    //success
}

If you wanna throw an exception (Attw\File\Validator\Exception\FileValidatorException) when the validation fail, execute the method Attw\File\Validator\SomeValidator::exception($on = false) with the param $on as true., (*10)

The Versions

28/09 2014

dev-master

9999999-dev http://attwframework.github.io

File component of AttwFramework

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

framework-component