dev-master
9999999-dev http://attwframework.github.ioFile component of AttwFramework
MIT
The Requires
- php >=5.3.0
framework-component
Wallogit.com
2017 © Pedro Peláez
File component of AttwFramework
File component of AttwFramework., (*2)
{
"require": {
"attwframework/file": "dev-master"
}
}
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)
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
}
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)
File component of AttwFramework
MIT
framework-component