NewUpload Behavior

An Upload Behavior for CakePHP 2.0.

This behavior allows you to optionally store in a database the information about your uploads.

Dependencies

  • CakePHP 2.0
  • PHP 5.3

HowTo

Installation

Get a copy of the code on GitHub.

Some methods to get code:

  • Download the source code at this link: Download code from the branch master
  • Add it as a submodule of your project:
    git submodule add git://github.com/vitorpc/NewUpload.git Plugin/NewUpload
  • Make a clone of the project:
    git clone git://github.com/vitorpc/NewUpload.git Plugin/NewUpload
  • Add to your Config/bootstrap.php the following code:
    CakePlugin::load('NewUpload');

Usage

You must specify the property $actsAs in their model.

Basic

class Image extends AppModel {
	public $actsAs = array(
		'NewUpload.NewUpload' => array('file')
	);
}
											

Full Usage

class Image extends AppModel {
	public $actsAs = array(
		'NewUpload.NewUpload' => array(
			'file' => array(
				// you can use shortcuts like: {DS} and {ModelName}
				'dir' => '/path/to/images/folder/',		
				// can be 'fix' or 'random'
				'adjustFilename' => 'fix',
				// fields of database
				'fields' => array(
					// type: VARCHAR(255)
					'dir' => 'dir_field',
					// type: VARCHAR(255)
					'mimetype' => 'mimetype_field',
					// type: INT
					'size' => 'size_field,
				), 
			)
		)
	);
}
											

View

In your view, you must define the type of form and field to file, if you are using the additional fields they should be defined as hidden.

echo $this->Form->create('Image', array('type' => 'file'));
echo $this->Form->input('image', array('type' => 'file'));
echo $this->Form->input('dir', array('type' => 'hidden'));
echo $this->Form->input('mimetype', array('type' => 'hidden'));
echo $this->Form->input('size', array('type' => 'hidden'));

License

MIT License (http://www.opensource.org/licenses/mit-license.php)

Authors

Vitor Pacheco (vitor-p.c@hotmail.com)

Contact

Vitor Pacheco (vitor-p.c@hotmail.com)

Download

You can download this project in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://github.com/vitorpc/NewUpload