infw / file
File Object for In Framework
Installs: 5 822
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^5.6|^7.0
- infw/range: ^0.0.1
- infw/size: ^0.0.1
Requires (Dev)
- henrikbjorn/phpspec-code-coverage: ^3.0
- memio/spec-gen: ^0.6
- phpspec/phpspec: ^3.0
This package is auto-updated.
Last update: 2024-11-18 09:17:00 UTC
README
File is a useful object used as base file at "In Framework" FileManager.
It can be very useful to validate file uploads.
Package contains two generic file types GenericFile
and Base64File
.
Installation
composer require infw/file
Usage
<?php use InFw\File\BaseMimeTypeFactory; use InFw\Size\BaseSizeFactory; use InFw\File\MimeTypes; use InFw\File\GenericFileFactory; $config = [ 'min_size' => 20, 'max_size' => 140000 ]; $mime = new BaseMimeTypeFactory( MimeTypes::IMAGES ); $size = new BaseSizeFactory( $config['min_size'], $config['max_size'] ); // Assuming your form has an input type=file field named "upload" and an input type=name named "file_name". $fileFactory = new GenericFileFactory($mime, $size); /** @var \InFw\File\FileInterface $file */ $file = $fileFactory->make($_FILES['upload'][0]['tmp_name'], $_POST['file_name']); $file->getName(); $file->getMimeType(); $file->getSize(); $file->getTmpName();