Simplified attachments

This commit is contained in:
Karl Cordes 2013-04-04 21:54:28 +11:00
parent bdbec2b9b3
commit 59090dc452
3 changed files with 55 additions and 68 deletions

View file

@ -52,8 +52,6 @@ if($host == 'cmc.lan') {
$basedir = '/var/www/CMC-Sales/app';
Configure::write('email_directory', '/var/www/cakephp/app/emails');
Configure::write('pdf_directory', $basedir.'/webroot/pdf/');
Configure::write('attachments_directory', $basedir.'/attachments_files/');
Configure::write('smtp_settings', array(
'port' => '25',
@ -76,22 +74,6 @@ if($host == 'cmc.lan') {
else { //Staging config
$basedir = '/home/karlcordes/CMC-Sales/app/';
Configure::write('smtp_settings', array(
'port' => '1025',
'timeout' => '30',
'host' => 'localhost'));
/**
*
* Cache Engine Configuration
* Default settings provided below
*
* File storage engine.
*/
Cache::config('default', array(
'engine' => 'File', //[required]
'duration'=> 3600, //[optional]
@ -105,6 +87,10 @@ else { //Staging config
Configure::write('pdf_directory', $basedir.'/webroot/pdf/');
Configure::write('attachments_directory', $basedir.'/webroot/attachments_files/');
// $output_dir = '/var/www/cakephp/app/webroot/pdf/';
/**

View file

@ -22,8 +22,10 @@ class AttachmentsController extends AppController {
if (!empty($this->data)) {
$attachment = $this->Attachment->process_attachment($this->data);
if(!$attachment) {
$this->Session->setFlash('The Attachment could not be saved. The filename exists');
}
else {
$this->Attachment->create();
if ($this->Attachment->save($attachment)) {
@ -33,6 +35,7 @@ class AttachmentsController extends AppController {
$this->Session->setFlash(__('The Attachment could not be saved. Please, try again.', true));
}
}
}
$principles = $this->Attachment->Principle->find('list');
$this->set(compact('products', 'principles'));
}
@ -62,7 +65,9 @@ class AttachmentsController extends AppController {
$this->Session->setFlash(__('Invalid id for Attachment', true));
$this->redirect(array('action'=>'index'));
}
$attachment = $this->Attachment->read(null, $id);
if ($this->Attachment->del($id)) {
unlink($attachment['Attachment']['file']);
$this->Session->setFlash(__('Attachment deleted', true));
$this->redirect(array('action'=>'index'));
}

View file

@ -54,22 +54,18 @@ class Attachment extends AppModel {
$upload = $attachment['Attachment']['file'];
$new_filename = Configure::read('attachments_directory').time().$upload['name'];
$new_filename = Configure::read('attachments_directory').$upload['name'];
if(!file_exists($new_filename)) {
move_uploaded_file($upload['tmp_name'], $new_filename);
$moved = move_uploaded_file($upload['tmp_name'], $new_filename);
if($moved) {
$attachment['Attachment']['filename'] = $upload['name'];
$attachment['Attachment']['file'] = $new_filename;
$attachment['Attachment']['size'] = $upload['size'];
$attachment['Attachment']['type'] = $upload['type'];
return $attachment;
}
else {
die("Error! Unable to move the uploaded file");
}
}
return false;
}