Downloads

Google Ad

2.0.1: FileUploadHelper Released

Date: Wed, Apr 22nd 2009, 22:16 Author: nick Views: 6497 Comments share

CakePHP File Upload Plugin

Info:
Watch:
Get it:
  • Download Now
  • git clone git://github.com/webtechnick/CakePHP-FileUpload-Plugin file_upload
The newest 2.0.1 release of File Upload Component now features a helper for more streamline setup and management of all your file uploading needs in CakePHP.

This new helper introduces two new features to utilize.

1) Automatic image resizing (thumbnails) for upload images (requires the GD Library). If there is no GD library present the helper uses browser resizing.
  1. $fileUpload->image($name_or_id, $options = array());

2) Input field configured based on your component configuration.
  1. $fileUpload->input($options = array());


Image examples: Resizes, saves (to your uploadDir), and displays 'image.jpg' to width 250 (if GD library is installed).
  1. $fileUpload->image('image.jpg', array('width' => 250));
  2. //outputs <img src="/files/image.jpgx250.jpg" alt="" />

If you have a custom uploadDir for each file you can set it in the options.
  1. $fileUpload->image('image.jpg', array('width' => 250, 'uploadDir' => 'uploads'));
  2. //outputs <img src="/uploads/image.jpgx250" alt="" />

You can pass any other options as you would an html->image call
  1. $fileUpload->image('image.jpg', array('width' => 250, 'alt' => 'image', 'id' => 'the_image'));
  2. //outputs <img src="image.jpgx250.jpg" alt="image" id="the_image" />

You can pass an id instead of a filename to the image helper as well.
  1. $fileUpload->image(2);


File Input Examples fileUpload->input() defaults to your default FileUploadComponent configuration. (ie. fileModel => 'Upload', fileVar => 'file'). Changing your default FileUploadComponent configuration will also change the default FileUploadHelper input. YAY!
  1. $fileUpload->input();
  2. //output <input type="file" name="data[Upload][file]" />

You can pass custom fields into the input.
  1. $fileUpload->input(array('var' => 'fileVar', 'model' => 'Picture'));
  2. //output <input type="file" name="data[Picture][fileVar]" />

You can pass any other options as you would into $form->input()
  1. $fileUpload->input(array('label' => 'Picture Upload', 'div' => false));


I hope you find the auto image thumbnails and input useful. I will be adding a new article soon.