1. Copy the plugin to the appropriate directory
Plugin and vendor
2. Add load file to core.php
Require_once dirname (__dir__). '/vendor/autoload.php ';
3.model Add the following two parts
Uploading components
App::uses (' Attachmentbehavior ', ' uploader.model/behavior ');
Cakeplugin::load (' Uploader ');
App::uses (' Vendor ', ' uploader.uploader ');
Public $actsAs = Array (
' Uploader.attachment ' = Array (
Don't copy all these settings, it's merely an example
' Image ' = = Array (
Variables that are used in view files to accept uploaded files
' Finalpath ' = '/files/upload/',//This is a relative path
' Finalpath ' = '/img/uploads/',
' prepend ' = ' upload-',
' NameCallback ' = ' formatname ',
' NameCallback ' = ' formatname ',
' extension ' = = Array (' gif ', ' jpg ', ' png ', ' jpeg '),//acceptable file format, user customizable
' FileSize ' = 5242880,//File size not exceeding 5M
' DbColumn ' = ' image ',//model corresponding to the database field
' Maxnamelength ' = 50,//default is 30
' Overwrite ' = = true,//the same file name will overwrite
' Stopsave ' = true,//If the upload is unsuccessful, automatically stops saving the entire form
' AllowEmpty ' = true,
' Transforms ' = Array (
' Imagemedium ' = Array (
' DbColumn ' = ' image ',
' Class ' = ' resize ',
' Append ' = '-medium ',
' Overwrite ' = true,
' Width ' = 390,
' Height ' = 300,
' Aspect ' = False,
' Self ' = True
)
)
)
)
);
Public Function FormatName ($name, $file) {
Return sprintf ('%s ', date ("y/m/d/g/i/s"));
}
4.view add
echo $this->form->create (' Yaop ', Array (' type ' = ' file ',
' Inputdefaults ' = Array (
' div ' = false,
' ERROR ' = = Array (' attributes ' + = Array (' wrap ' = ' div ', ' class ' = ' Validate_error ')
)
));
echo $this->form->input (' image ', array (' type ' = ' file ', ' div ' = = false, ' label ' =>false));
Author Address:
Http://milesj.me/code/cakephp/uploader
CakePHP Upload Components Tutorial