2017 © Pedro Peláez
 

cakephp-plugin database-blob-file

Store uploads from cakephp as blob/binary in the database

image

elic-dev/database-blob-file

Store uploads from cakephp as blob/binary in the database

  • Friday, February 12, 2016
  • by elic-dev
  • Repository
  • 2 Watchers
  • 0 Stars
  • 1,468 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Database Blob File

This plugin is in a very early stage and should not be used for production environment., (*1)

Store your uploads from CakePHP form helper directly in the database as binary object., (*2)

If you still consider that all uploaded files have to be stored in the filesystem you can ignore this plugin., (*3)

Install

This Plugin requires CakePHP 2., (*4)

Enable Plugin

Enable to plugin in your bootstrap.php file. Routes are required for serving uploaded files via http., (*5)

CakePlugin::load('DatabaseBlobFile', array(
    'routes'    => true,
    'bootstrap' => true,
));

Create a BLOB column

Change or add an column in your database as MEDIUMBLOB (max. 16MB file size)., (*6)

Add the behavior to your Model

Tell the Model to load the behavior for saving files directly., (*7)

public $actsAs = array(
    'DatabaseBlobFile.BlobFile' => array(
        'imageMaxWidth' => 1000,
    )
);

You can set addional parameters like:, (*8)

imageMaxWidth Resize uploaded images to have a maximum width., (*9)

Form

And make sure your form created with a correct type to allow file uploads at all., (*10)

<?php echo $this->Form->create('Object',array('type'=>'file')); ?>

Add your form field with the form helper, (*11)

<?php echo $this->Form->input('column_name'); ?>

Using the plugin

Because it is not necessary to transfer all files with every database select every time the model returns only the uploaded file size in byte. This can be usefull to decide if something has been uploaded at all., (*12)

You will have a new virtual field containing a base path to the file (will be replaced with a View helper function) in your database result., (*13)

<?php echo $this->Html->image($model['Table']['columnname_basepath'].'size.jpg')

Output images in different sizes

resize

Maintains the aspect ration of the image and makes sure that it fits within the new max width and max height (thus some side will be smaller)., (*14)

resizefit

Maintains the aspect ration of the image and makes sure that it fits inside the new width and height. Extra space will be filled with white color., (*15)

resizewidth

Maintains aspect ratio but resizes the image so that the Width has to fit. We don't care about the height., (*16)

resizemin

Maintains aspect ratio but resizes the image so that once one side meets its maxW or maxH condition, it stays at that size (thus one side will be larger)., (*17)

crop

Simple center crop, (*18)

resizecrop

resize to max width and height, then crop to center, (*19)

Caching

Every file which has been served once will be stored inside the webroot for caching with a timestamp. This is supposed to work with a deployment processes which resets the app folder to its correct state with every deployment., (*20)

Cache using CDN

You can set a CDN host address inside your config file. This will reduce request to your server and files stored inside your webroot., (*21)

Roadmap

  • Support for more file types than just images
  • More config options for caching and serving files (use subdomain, path and cdn)

The Versions

12/02 2016

2.x-dev

2.9999999.9999999.9999999-dev

Store uploads from cakephp as blob/binary in the database

  Sources   Download

MIT

The Requires

 

by Matthias Lill

12/02 2016

dev-master

9999999-dev

Store uploads from cakephp as blob/binary in the database

  Sources   Download

MIT

The Requires

 

by Matthias Lill