cmc-sales/controllers/email_attachments_controller.php

66 lines
1.4 KiB
PHP
Raw Normal View History

2009-02-09 14:25:49 -08:00
<?php
class EmailAttachmentsController extends AppController {
2010-04-26 23:49:20 -07:00
var $name = 'EmailAttachments';
var $helpers = array('Html', 'Form');
2009-02-09 14:25:49 -08:00
2011-03-09 23:18:26 -08:00
2010-04-26 23:49:20 -07:00
function download($id) {
2010-05-10 22:02:11 -07:00
2011-03-09 23:18:26 -08:00
$file = $this->EmailAttachment->findById($id);
$file_path = Configure::read('email_directory');
if(file_exists($file_path."/".$file['EmailAttachment']['name'])) {
Configure::write('debug', 0);
if(!$file['EmailAttachment']['filename']) {
$filename = 'vault_'.time();
}
else {
$filename = $file['EmailAttachment']['filename'];
}
header('Content-type: ' . $file['EmailAttachment']['type']);
header('Content-length: ' . $file['EmailAttachment']['size']);
header('Content-Disposition: attachment; filename='.$filename);
readfile($file_path."/".$file['EmailAttachment']['name']);
exit();
}
else {
echo "ERROR!! : File Not Found";
echo $file['EmailAttachment']['filename'];
die();
}
2010-04-26 23:49:20 -07:00
}
2009-02-09 14:25:49 -08:00
2011-03-09 23:18:26 -08:00
function view($id = null) {
Configure::write('debug', 0);
$this->layout = 'minimal';
if(!$id) {
return;
}
else {
$file = $this->EmailAttachment->find('first', array('conditions'=>array('EmailAttachment.id'=>$id)));
//$this->set('attachment', $file);
$file_path = Configure::read('email_directory');
$contents = file_get_contents($file_path."/".$file['EmailAttachment']['name']);
$this->set('contents', $contents);
}
}
2009-02-09 14:25:49 -08:00
}