cmc-sales/app/controllers/email_attachments_controller.php

72 lines
1.5 KiB
PHP
Raw Normal View History

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