PHP code example of cobaia / attach
1. Go to this page and download the library: Download cobaia/attach library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cobaia / attach example snippets
App::uses('AppModel', 'Model');
class Media extends AppModel {
public $validate = array(
'image' => array(
'extension' => array(
'rule' => array(
'extension', array(
'jpg',
'jpeg',
'bmp',
'gif',
'png',
'jpg'
)
),
'message' => 'File extension is not supported',
'on' => 'create'
),
'mime' => array(
'rule' => array('mime', array(
'image/jpeg',
'image/pjpeg',
'image/bmp',
'image/x-ms-bmp',
'image/gif',
'image/png'
)),
'on' => 'create'
),
'size' => array(
'rule' => array('size', 2097152),
'on' => 'create'
)
),
'swf' => array(
'extension' => array(
'rule' => array(
'extension', array(
'swf',
)
),
'message' => 'File extension is not supported',
'on' => 'create'
),
'mime' => array(
'rule' => array('mime', array(
'application/x-shockwave-flash',
)),
'on' => 'create'
),
'size' => array(
'rule' => array('size', 53687091200),
'on' => 'create'
)
),
'zip' => array(
'extension' => array(
'rule' => array(
'extension', array(
'zip',
)
),
'message' => 'File extension is not supported',
'on' => 'create'
),
'mime' => array(
'rule' => array('mime', array(
'application/zip',
'multipart/x-zip'
)),
'on' => 'create'
),
'size' => array(
'rule' => array('size', 53687091200),
'on' => 'create'
)
),
);
public $actsAs = array(
'Attach.Upload' => array(
'Attach.type' => 'Imagick', //you can choose btw Imagick or Gd to handle the thumbnails, in case you do not pass that default is GD
'swf' => array(
'dir' => 'webroot{DS}uploads{DS}media{DS}swf'
),
'image' => array(
'dir' => 'webroot{DS}uploads{DS}media{DS}image',
'thumbs' => array(
'thumb' => array(
'w' => 190,
'h' => 158,
'crop' => true,
),
),
),
'zip' => array(
'dir' => 'webroot{DS}uploads{DS}media{DS}zip'
),
),
);
echo $this->Form->create('Media', array('type' => 'file'));
echo $this->Form->input('name');
echo $this->Form->input('image', array('type' => 'file'));
echo $this->Form->input('swf', array('type' => 'file'));
echo $this->Form->input('zip', array('type' => 'file'));
echo $this->Form->input('status');
echo $this->Form->end(__('Submit'));
var_dump($this->Media->AttachmentImage);
var_dump($this->Media->AttachmentSwf);
var_dump($this->Media->AttachmentZip);
cake.php schema create --plugin Attach