承接 stanislav-web/phalcon-uploader 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

stanislav-web/phalcon-uploader

最新稳定版本:v1.4-beta

Composer 安装命令:

composer require stanislav-web/phalcon-uploader

包简介

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

README 文档

README

Scrutinizer Code Quality Code Coverage Total Downloads Latest Unstable Version

Description

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

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:

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

Then run to update dependency and autoloader

php composer.phar update
php composer.phar install

or just

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

(Do not forget to include the composer autoloader)

Or manual require in your loader service

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

You can create an injectable service

    $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

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

Read logs from phpunit/log

##Change Log

##Issues

MIT License

统计信息

  • 总下载量: 36.37k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 64
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 5

GitHub 信息

  • Stars: 63
  • Watchers: 4
  • Forks: 10
  • 开发语言: HTML

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-11