2017 © Pedro Peláez
 

library phalcon-uploader

Phalcon files uploader. Handling and downloading files for Phalcon projects. Allowed multiple files download, filters etc...

image

stanislav-web/phalcon-uploader

Phalcon files uploader. Handling and downloading files for Phalcon projects. Allowed multiple files download, filters etc...

  • Friday, September 18, 2015
  • by stanislav-web
  • Repository
  • 5 Watchers
  • 61 Stars
  • 7,058 Installations
  • HTML
  • 3 Dependents
  • 5 Suggesters
  • 14 Forks
  • 2 Open issues
  • 8 Versions
  • 6 % Grown

The README.md

Phalcon File Uploader

Scrutinizer Code Quality Code Coverage Total Downloads Latest Unstable Version, (*1)

Description

Handling and downloading files for Phalcon projects. Allowed multiple files, filters etc.... (Currently under TDD), (*2)

Change Log

[v 1.4-beta] 2015-05-28

- ability to download files to a dynamically created directory (by [Mahdi-Mohammadi](https://github.com/Mahdi-Mohammadi))

[v 1.3-beta] 2015-05-07

- it support Phalcon 2.0

[v 1.2-beta] 2015-05-07

- ability to use closure (anonimous function) for generate uploaded file name

[v 1.1-beta] 2015-02-23

- ability to delete files after downloading ($uploader->truncate())

[v 1.0-beta] 2015-01-10

- added validator (sizes, extensions, mime types, directory upload)
- added filters (sanitize filename pre save, hash filename)

Compatible

  • PSR-0, PSR-1, PSR-2, PSR-4 Standards

System requirements

  • PHP 5.4.x >
  • Phalcon extension 1.3.x

Install

First update your dependencies through composer. Add to your composer.json:, (*3)

"require": {
    "stanislav-web/phalcon-uploader": "1.*",
}

Then run to update dependency and autoloader, (*4)

php composer.phar update
php composer.phar install

or just, (*5)

php composer.phar require stanislav-web/phalcon-uploader dev-master 

(Do not forget to include the composer autoloader), (*6)

Or manual require in your loader service, (*7)

    $loader->registerNamespaces([
        'Uploader\Uploader' => 'path to src'
    ]);

You can create an injectable service, (*8)

    $di->set('uploader', '\Uploader\Uploader');

Usage

Simple usage

 <?php

 if($this->request->hasFiles() !== false) {

    // get uploader service
    $uploader = $this->di->get('uploader');

    // setting up uloader rules
    $uploader->setRules([
        'directory' =>  '/files',
        //or 'dynamic'   =>  '/files/'.$part.'/'.$userId, // added v1.4-beta
    ]);

    // or use constructor if you don't use service
    $uploader = new \Uploader\Uploader(([
        'directory' =>  '/files',
        //or 'dynamic'   =>  '/files/'.$part.'/'.$userId, // added v1.4-beta
    ]);

 }

Filters

 <?php

 if($this->request->hasFiles() !== false) {

    // get uploader service or \Uploader\Uploader
    $uploader = $this->di->get('uploader');

    // setting up uloader rules
    $uploader->setRules([
        'directory' =>  '/files',
        //or 'dynamic'   =>  '/files/'.$part.'/'.$userId, // added v1.4-beta
        'minsize'   =>  1000,   // bytes
        'maxsize'   =>  1000000,// bytes
        'mimes'     =>  [       // any allowed mime types
            'image/gif',
            'image/jpeg',
            'image/png',
        ],
        'extensions'     =>  [  // any allowed extensions
            'gif',
            'jpeg',
            'jpg',
            'png',
        ],  

        'sanitize' => true  // escape file & translate to latin  
        'hash'     => 'md5'  // save file as hash (default md5) you can use ANY function to handle filename
    ]);
 }

Full Handle

 <?php

 if($this->request->hasFiles() !== false) {

    // get uploader service or \Uploader\Uploader
    $uploader = $this->di->get('uploader');

    // setting up uloader rules
    $uploader->setRules([
        'directory' =>  '/files',
        //or 'dynamic'   =>  '/files/'.$part.'/'.$userId, // added v1.4-beta
        'minsize'   =>  1000,   // bytes
        'maxsize'   =>  1000000,// bytes
        'mimes'     =>  [       // any allowed mime types
            'image/gif',
            'image/jpeg',
            'image/png',
        ],
        'extensions'     =>  [  // any allowed extensions
            'gif',
            'jpeg',
            'jpg',
            'png',
        ],  

        'sanitize' => true
        'hash'     => 'md5'
    ]);

    if($uploader->isValid() === true) {

        $uploader->move(); // upload files array result

        $uploader->getInfo() // var dump to see upload files

    }
    else {
        $uploader->getErrors(); // var_dump errors
    }
 }

 // you always can remove all files uploaded by one iteration 
 $uploader->truncate(); // added 1.1

Unit Test

Also available in /phpunit directory. Run command to start, (*9)

php build/phpunit.phar --configuration phpunit.xml.dist --coverage-text

Read logs from phpunit/log, (*10)

Change Log

Issues

MIT License, (*11)

The Versions

18/09 2015

dev-master

9999999-dev https://github.com/stanislav-web/phalcon-uploader

Phalcon files uploader. Handling and downloading files for Phalcon projects. Allowed multiple files download, filters etc...

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

uploader phalcon phalcon uploader phalcon upload phalcon upload files

02/09 2015

1.1.x-dev

1.1.9999999.9999999-dev https://github.com/stanislav-web/phalcon-uploader

It is fork of stanislav-web/phalcon-uploader. Phalcon files uploader. Handling and downloading files for Phalcon projects. Allowed multiple files download, filters etc...

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

uploader phalcon phalcon uploader phalcon upload phalcon upload files

30/06 2015

dev-revert-4-master

dev-revert-4-master https://github.com/stanislav-web/phalcon-uploader

Phalcon files uploader. Handling and downloading files for Phalcon projects. Allowed multiple files download, filters etc...

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

uploader phalcon phalcon uploader phalcon upload phalcon upload files

28/05 2015

v1.4-beta

1.4.0.0-beta https://github.com/stanislav-web/phalcon-uploader

Phalcon files uploader. Handling and downloading files for Phalcon projects. Allowed multiple files download, filters etc...

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

uploader phalcon phalcon uploader phalcon upload phalcon upload files

07/05 2015

1.3-beta

1.3.0.0-beta https://github.com/stanislav-web/phalcon-uploader

Phalcon files uploader. Handling and downloading files for Phalcon projects. Allowed multiple files download, filters etc...

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

uploader phalcon phalcon uploader phalcon upload phalcon upload files

07/05 2015

1.2-beta

1.2.0.0-beta https://github.com/stanislav-web/phalcon-uploader

Phalcon files uploader. Handling and downloading files for Phalcon projects. Allowed multiple files download, filters etc...

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

uploader phalcon phalcon uploader phalcon upload phalcon upload files

23/02 2015

1.1-beta

1.1.0.0-beta https://github.com/stanislav-web/phalcon-uploader

Phalcon files uploader. Handling and downloading files for Phalcon projects. Allowed multiple files download, filters etc...

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

uploader phalcon phalcon uploader phalcon upload phalcon upload files

11/01 2015

1.0-beta

1.0.0.0-beta https://github.com/stanislav-web/phalcon-uploader

Phalcon files uploader. Handling and downloading files for Phalcon projects. Allowed multiple files download, filters etc...

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

uploader phalcon phalcon uploader phalcon upload phalcon upload files