定制 cjci/res_storage 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

cjci/res_storage

Composer 安装命令:

composer require cjci/res_storage

包简介

CodeIgniter Resource management library. Store files using Encryption and handle file metadata.

README 文档

README

Resource Management Class for Codeigniter framework. It allows to store and process files w/wo encryption

What is CI Resource Management

This is a library coded to work in CodeIgniter Framework that helps in the process of management resources - files - and storing them in your filesystem with or without encryption. By default it uses rijndael-256 - commonly known as AES256 - to store files.

If your web application handles a lot of files, that you must secure in some way and want to have a common library to do all the hard work of storing and encrypting files in your application. This library is for you.

Installation

1.a (If you use composer) Execute: composer require cjci/res_storage and fill in your desired version (dev-master for latest changes).

1.b (Manually) Download desired version of this project to application/libraries/

  1. Create your own res_storage.php config file in application/config to configure your path and encryption key. (see Usage for more details)

Usage

Codeigniters wrapper to loader class

This class can be used in anywhere in your code just by its FQNS CJCI/ResStorage/ResStorage But, if you want to use $this->load->('res_storage') in your code, because you are familiar with CI Loader. Just create a res_storage.php file in your application/libraries folder. Contents as follows:

<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

use CJCI\ResStorage\ResStorage;

class res_storage extends ResStorage{}

Now we need to configure where to store files and a new clear secretkey. (It will be the basis of a new hashed secret key)

Creating a res_storage.php file in your CodeIgniter's config dir:

$config['clearkey'] = "YourSecretKey" ;

$config['storage_dir'] = "/Path/To/Your/Filesystem/";

Or as a parameter when using CI Loader Class:

$this->load->library('res_storage',array('clearkey' => 'MyKey','storage_dir' => '/Path'));

Instantiate $this->load->library('res_storage');

Store a file When storing files it will store a copy of that file. It wont move or delete original file. $uuid = $this->res_storage->store_file('/Path/to/File.txt');

$uuid is auniq a string identifier that identifies that file in the future.

Storing a file will store a copy of a document. using a file handler class (Encrypted AES256 32IV by default) And also will store metadata of that document into res_storage table.

Read Metadata var_dump($this->res_storage->metadata($uuid));

Returns

array(10) { 
		["id"]=> string(1) "8" 
		["uuid"]=> string(23) "52825331913af4.96762038" 
		["filename"]=> string(22) "logo_entry_transparent.jpg" 
		["path"]=> string(46) "/var/www/webpage/resources/827/c0b/b38/" 
		["mimetype"]=> string(10) "image/jpeg" 
		["hash"]=> string(32) "827c0bb38c277eb592ff122b39b67d9e" 
		["b64_iv"]=> string(44) "maasdaX7JsfsGJvgcMhX2jBRkm2N4SV7523sYgP6Pb7gZN89Xa62mU=" 
		["accessed"]=> string(1) "0" 
		["stored"]=> string(19) "2013-08-01 20:11:29" 
		["lastaccess"]=> string(19) "2013-08-01 20:11:29" 
	}

Get File contents $contents = $this->res_storage->file_get_contents($uuid);

Output contents to browser using metadata Uses metadata to write some headers and then file contents $this->res_storage->readfile($uuid);

Delete File $this->res_storage->delete($uuid)

Everything will throw an Exception if something goes wrong. So if you want to be safe and not have halfloaded pages... try using try-catch:

	 try{
                return $this->res_storage->readfile($uuid);
            }catch (Exception $e) {
                error_log ('/* Captured: ',  $e->getMessage(), "*/ \n");
                http_response_code(404);
                die("File not found.");
            }

Creating your own FileHandle with your own encryption

Extend and include somewhere in your code RSFile Class if you don't want to use MCRYPT to store your files encrypted. Otherwise extend RSFileEncrypted and modify it's properties to fit your needs.

Add to your config/res_storage.php: $config['file_handler'] = 'My_File_Handler' ;

Or Extend ResStorage and override the following to use your FileHandler:

use CJCI\ResStorage\ResStorage;
class My_Storage extends ResStorage {
	/**
     * Class to use to handle phisically files. Default RSFileEncrypted
	 * use RSFile for non encrypted handling. (or write your own!)Where files will be stored.
     * FileClass
     * @access public
     * @var string
     */
	public $FileClass    = "MY_File_Handler";
}

License

GPL V3

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: JavaScript

其他信息

  • 授权协议: GPL3
  • 更新时间: 2013-11-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固