Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Upload Behavior for CakePHP 2.0
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
Model
Test
.gitignore
README.textile

README.textile

NewUpload Behavior

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

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


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

Full Usage


<?php
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.


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

Copyright

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

Something went wrong with that request. Please try again.