2017 © Pedro Peláez
 

library uploader

Basic PHP library to upload files using different sources

image

uploader/uploader

Basic PHP library to upload files using different sources

  • Thursday, July 7, 2016
  • by oscarotero
  • Repository
  • 2 Watchers
  • 3 Stars
  • 571 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 5 % Grown

The README.md

uploader

Basic php library to manage uploaded files, (*1)

Scrutinizer Code Quality, (*2)

Created by Oscar Otero http://oscarotero.com oom@oscarotero.com, (*3)

Basic usage

//Init a Uploader instance:
$uploader = new Uploader\Uploader('/base/path/to/uploads');

//Save an uploaded file:
$file = $uploader($_FILES['my-file']);

//Save a psr7 UploadedFileInterface instance
$file = $uploader($uploadedFile);

//Save a file from an url
$file = $uploader('http://example.com/files/file1.jpg');

//Save from base64 value
$file = $uploader('data:image/png;base64,...');

Advanced usage

//Init a Uploader instance:
$uploader = new Uploader\Uploader('/base/path/to/uploads');

//Add some configuration
$uploader
    ->setPrefix(function () {
        return uniqid();
    })
    ->setDirectory('images');

//Assign an input
$imageUpload = $uploader->with($_FILES['my-image']);

//Save
$imageUpload->save();

//Get the relative path
echo $imageUpload->getDestination();

API

The following methods configure how the uploaded file will be saved, (*4)

Setter Getter Description
`setPrefix(string Closure)` getPrefix() | Custom filename prefix.
`setOverwrite(boolean Closure)` getOverwrite() | Whether or not overwrite existing files
`setDestination(boolean Closure)` getDestination(bool $absolute = false) | The destination file. If $absolute is true, returns the path with the cwd
`setDirectory(string Closure)` getDirectory() | To change only the directory of the destination
`setFilename(string Closure)` getFilename() | To change only the filename of the destination
`setExtension(string Closure)` getExtension() | To change only the file extension of the destination
`setCwd(string Closure)` getCwd() | To change the base path of the destination
`setCreateDir(boolean Closure)` getCreateDir() | Whether or not create the destination directory if it does not exist

Example:, (*5)

$uploader = new Uploader\Uploader(__DIR__.'/my-uploads');

$upload = $uploader
    ->with($_FILES['my-file'])
    ->setPrefix(uniqid())
    ->setOverwrite(true)
    ->setCreateDir(true)
    ->setDirectory('files')
    ->setExtension(function ($upload) {
        return strtolower($upload->getExtension());
    });

try {
    $upload->save();

    echo 'The file has been saved in '.$upload->getDestination();
} catch (Exception $e) {
    echo $e->getMessage();
}

The Versions

07/07 2016

dev-master

9999999-dev https://github.com/fol-project/fol

Basic PHP library to upload files using different sources

  Sources   Download

MIT

The Requires

 

framework

07/07 2016

v1.4.1

1.4.1.0 https://github.com/fol-project/fol

Basic PHP library to upload files using different sources

  Sources   Download

MIT

The Requires

 

framework

15/12 2015

v1.4.0

1.4.0.0 https://github.com/fol-project/fol

Basic PHP library to upload files using different sources

  Sources   Download

MIT

The Requires

 

framework

25/06 2015

v1.3

1.3.0.0 https://github.com/fol-project/fol

Basic PHP library to upload files using different sources

  Sources   Download

MIT

The Requires

 

framework

02/05 2015

v1.2

1.2.0.0 https://github.com/fol-project/fol

Basic PHP library to upload files using different sources

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework

25/04 2015

v1.1

1.1.0.0 https://github.com/fol-project/fol

Basic PHP library to upload files using different sources

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework

25/04 2015

v1.0.1

1.0.1.0 https://github.com/fol-project/fol

Basic PHP library to upload files using different sources

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework

28/03 2015

v1.0

1.0.0.0 https://github.com/fol-project/fol

Basic PHP library to upload files using different sources

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

framework