zaszczyk/phalcon-uploader 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

zaszczyk/phalcon-uploader

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

Composer 安装命令:

composer require zaszczyk/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...

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

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 11
  • 开发语言: HTML

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固