joacub/file-bank 问题修复 & 功能扩展

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

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

joacub/file-bank

Composer 安装命令:

composer require joacub/file-bank

包简介

A Zend Framework 2 module for uploading files to a File Bank along with metadata, keywords and status information and a controller to offer saved files for download.

关键字:

README 文档

README

BASED ON FILEBANK

This module provides a way to store files in a structured database and file accessors to obtain the file for download or display without the need to setup public folders and worry about security and htaccess configurations.

View Helper is also provided for access to file's download URL as well as file information.

This module is in active development stage. See the bottom of this README for upcoming features.

Requirements:

  • PHP 5.3
  • Zend Framework 2
  • Doctrine 2

See https://github.com/artur-gajewski/FileBank

Follow me on twitter: @GajewskiArtur

Installation with Composer

Go to your project directory and add the following line to "require" list in composer.json file:

"artur-gajewski/file-bank": "dev-master"

Now run the Composer:

php composer.phar install

Then add 'FileBank' into the Module array in APPLICATION_ROOT/config/application.config.php

<?php
return array(
    'modules' => array(
        ...
        'FileBank',
        ...
    ),
);

Next, create a new table in your application's MySQL database by running the two queries in data/create_scema.sql file:

CREATE TABLE filebank (
  id int(11) NOT NULL auto_increment,
  name varchar(250) NOT NULL,
  size int(11) NOT NULL,
  mimetype varchar(250) NOT NULL,
  isactive int(11) NOT NULL,
  savepath varchar(250) NOT NULL,
  keywords varchar(500),
  PRIMARY KEY (id)
);

CREATE TABLE filebank_keyword (
  id int(11) NOT NULL auto_increment,
  fileid int(11) NOT NULL,
  value varchar(250),
  PRIMARY KEY (id)
);

Configuration of Doctrine and FileBank parameters

FileBank module uses Doctrine to access a database table specified for it. FileBank saves file information into database and functions are provided to utilize this information at any time.

The FileBank module package includes its own configuration in FileBank/config/module.config.php, but you should never touch any configurations found in modules installed under vendor directory.

Instead, if you want to override any configuration parameters provided with FileBank module, you should create a new configuration file APPLICATION_ROOT/config/autoload/FileBank.global.php

<?php
return array(
    ...
    'doctrine' => array(
        'connection' => array(
            'orm_default' => array(
                'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
                'params' => array(
                    'host'     => 'localhost',
                    'port'     => '3306',
                    'user'     => 'username',
                    'password' => 'password',
                    'dbname'   => 'database_name',
                )
            )
        ),
        ...

This will override the default settings of provided package with your own settings.

You can also modify default parameter settings that are provided with the package so that they would suit your needs. Such parameters are:

'params' => array(
        'filebank_folder'   => '/data/filebank/', 
        'default_is_active' => true,
        'chmod'             => 0755,
    ),
  • filebank_folder -> filebank root folder where the files will be saved to
  • default_is_active -> should the file be set as active by default
  • chmod -> after a folder is created, what chmod should it have

Accessing FileBank from a controller

FileBank module is accessible via Service Locator:

$fileBank = $this->getServiceLocator()->get('FileBank');

When you obtain the service and create the object, you can then use it to do the magic:

$entity = $fileBank->save('/tmp/myfile.jpg');

The return value is the file's FileBank entity from which you can get information usable in view helper.

You can also attach keywords for a file by adding an array to the save() function

$keywords = array('Foo', 'Bar', 'Hey');

$entity = $fileBank->save('/tmp/myfile.jpg', keywords);

This will attach these three keywords to the file. You can fetch the files with a certain keyword(s) as follows:

$fileBank->getFilesByKeywords(array('Foo', 'Hey'));

This will return an array of FileBank entities that match the keywords Foo and Hey. The keyword usage is case INSENSITIVE in both saving and fetching functions.

Downloading files from FileBank

This package comes along with router and controller to enable file downloads directory from view scripts. All you need to do is point your view script's link to:

http://YourApplication.com/files/<id>

ID is the identier for the file saved into FileBank.

In the view script, you can use FileBank's view helper, which returns file's entity:

<a href="<?php echo $this->getFileById(145)->getUrl(); ?>">Download <?php echo $this->getFileById(145)->getName(); ?></a>

Or, the file can be directly placed into IMG tag to display the image along with title data:

<img title="<?php echo $this->getFileById(145)->getName(); ?>" src="<?php echo $this->getFileById(145)->getUrl(); ?>"/>

Once a user clicks on this generated URL, a download prompt will appear and file is available for download.

Coming up...

Features to be added in some point:

  • Version control of uploaded files
  • Image editing with GD (multiple different sizes per saved image, configurable parameters)

Questions or comments?

Feel free to email me with any questions or comments about this module

info@arturgajewski.com

joacub/file-bank 适用场景与选型建议

joacub/file-bank 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 674 次下载、GitHub Stars 达 1, 最近一次更新时间为 2013 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「zf2」 「filebank」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 joacub/file-bank 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 joacub/file-bank 我们能提供哪些服务?
定制开发 / 二次开发

基于 joacub/file-bank 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2013-01-09