Skip to content

marciotrindade/cake_upload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Cake Upload

The Cake Upload is a component created to facilitate the uploading of files in projects that use CakePHP.

Installation

Component

To install the component you need execute :

git submodule add git@github.com:marciotrindade/cake_upload.git plugins/cake_upload
git submodule init
git submodule update

or download the zip and extract it in your plugins directory

Using

create an attribute $files in your controller like this.

var $files = array(
	"name_of_filed" => array(
		"new_name_of_file" => array($options)
	)
);

Options

type    => (move, fixed, resize or crop) how the plugin will process this file.
ext     => you can set how is the extension of file that you will create. Default is "jpg".
name    => you can set how is the name of file that you will create. Default is the key that you use on array (new_name_of_file).
mime    => you can set how is the mime type of file that you will create. Default is "image/jpeg".
width   => if you upload a image you can set a width to methods: fixed, resize or crop.
height  => if you upload a image you can set a height to methods: fixed, resize or crop.
quality => if you upload a image and choose "image/jpeg" to mime type you can set a quality your image.

Structure of folders

When you upload a file this plugin will create this structure in you webroot folder:

files/                       # folder to put uploaded files created by CakePHP
`-- pages                    # name of controller created by component
    `-- 3                    # id of record created by component
        `-- 0                # sequencial of files created by component (you can upload more than one file per record ex. press.pdf, example.doc and image.jpg)
            |-- big.jpg      # name and extension of file
            |-- image.jpg    # name and extension of file
            |-- origin.jpg   # name and extension of file
            `-- thumb.jpg    # name and extension of file

Example

<?php

class ProductsController extends AppController
{
	var $name = 'Products';
	var $components = array('Upload');
	var $files = array(
		"image_0" => array(
			"origin" => array("type" => "move"),
			"big" => array("type" => "resize", "width" => 900, "height"=>700),
			"image" => array("type" => "fixed", "width" => 273, "height"=>365),
			"thumb" => array("type" => "crop", "width"=>126, "height"=>157),
		),
		"image_1" => array(
			"origin" => array("type" => "move"),
			"big" => array("type" => "resize", "width" => 900, "height"=>700),
			"image" => array("type" => "fixed", "width" => 273, "height"=>365),
			"thumb" => array("type" => "crop", "width"=>126, "height"=>157),
		),
		"image_2" => array(
			"origin" => array("type" => "move"),
			"big" => array("type" => "resize", "width" => 900, "height"=>700),
			"image" => array("type" => "fixed", "width" => 273, "height"=>365),
			"thumb" => array("type" => "crop", "width"=>126, "height"=>157),
		)
	);

	function admin_add()
	{
		if (!empty($this->data))
		{
			$this->Product->create();
			if ($this->Product->save($this->data))
			{
				$this->data["Product"]["id"] = $this->Product->getLastInsertID();
				$this->Upload->upload();

				$this->Session->setFlash(__('The Product has been saved', true));
				$this->redirect(array("action"=>"index"));
			}
			else
			{
				$this->Session->setFlash(__("The Product could not be saved. Please, try again.", true));
			}
		}
	}

}
?>

About

Uploads com CakePHP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages