Find file
Fetching contributors…
Cannot retrieve contributors at this time
80 lines (65 sloc) 2.13 KB

NewUpload Behavior

An Upload Behavior for CakePHP 2.0
This behavior allows you to optionally store in a database the information about your uploads.


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:// Plugin/NewUpload
  • Make a clone of the project: git clone git:// Plugin/NewUpload
  • Add to your Config/bootstrap.php the following code: CakePlugin::load('NewUpload');


You must specify the property $actsAs in their model.


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,


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'));


This project is based on MeioUpload plugin of Juan Basso. The copyright of the code snippets derived from this plugin belongs to its author.