cmc-sales/php/app/models/attachment.php

74 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2012-11-18 12:19:55 -08:00
<?php
class Attachment extends AppModel {
var $name = 'Attachment';
var $validate = array(
'principle_id' => array('numeric'),
'name' => array('notempty'),
'type' => array('notempty'),
'size' => array('numeric'),
2013-04-04 03:54:28 -07:00
'archived' => array('numeric'),
2012-11-18 12:19:55 -08:00
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
'Principle' => array(
'className' => 'Principle',
'foreignKey' => 'principle_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
var $hasMany = array(
'DocumentAttachment' => array(
'className' => 'DocumentAttachment',
'foreignKey' => 'attachment_id'
2013-04-04 03:54:28 -07:00
)
2012-11-18 12:19:55 -08:00
);
2013-04-04 03:54:28 -07:00
// Based on comment 8 from: http://bakery.cakephp.org/articles/view/improved-advance-validation-with-parameters
2012-11-18 12:19:55 -08:00
2013-04-04 03:54:28 -07:00
function isUploadedFile($params){
$val = array_shift($params);
if ((isset($val['error']) && $val['error'] == 0) ||
(!empty( $val['tmp_name']) && $val['tmp_name'] != 'none')) {
return is_uploaded_file($val['tmp_name']);
}
return false;
}
2012-11-18 12:19:55 -08:00
2013-04-04 03:54:28 -07:00
/**
* Passed a PHP upload
* array('name', 'type', 'tmp_name', 'error' 'size').
*
* Move the uploaded file to the storage directory
* and return a cake array for insertion.
*
*/
2012-11-18 12:19:55 -08:00
2013-04-04 03:54:28 -07:00
function process_attachment($attachment) {
2012-11-18 12:19:55 -08:00
2013-04-04 03:54:28 -07:00
$upload = $attachment['Attachment']['file'];
2012-11-18 12:19:55 -08:00
2013-04-04 03:54:28 -07:00
$new_filename = Configure::read('attachments_directory').$upload['name'];
if(!file_exists($new_filename)) {
move_uploaded_file($upload['tmp_name'], $new_filename);
2012-11-18 12:19:55 -08:00
2013-04-04 03:54:28 -07:00
$attachment['Attachment']['filename'] = $upload['name'];
$attachment['Attachment']['file'] = $new_filename;
$attachment['Attachment']['size'] = $upload['size'];
$attachment['Attachment']['type'] = $upload['type'];
return $attachment;
2012-11-18 12:19:55 -08:00
2013-04-04 03:54:28 -07:00
}
return false;
2012-11-18 12:19:55 -08:00
2013-04-04 03:54:28 -07:00
}
2012-11-18 12:19:55 -08:00
}
?>