72 lines
1.6 KiB
PHP
Executable file
72 lines
1.6 KiB
PHP
Executable file
<?php
|
|
class EmailAttachmentsController extends AppController {
|
|
|
|
var $name = 'EmailAttachments';
|
|
var $helpers = array('Html', 'Form');
|
|
|
|
|
|
|
|
|
|
function download($id) {
|
|
|
|
$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: ' . filesize($file['EmailAttachment']['name']));
|
|
header('Content-Disposition: attachment; filename='.$filename);
|
|
|
|
readfile($file_path."/".$file['EmailAttachment']['name']);
|
|
|
|
exit();
|
|
}
|
|
else {
|
|
echo "ERROR!! : File Not Found";
|
|
echo $file['EmailAttachment']['filename'];
|
|
die();
|
|
}
|
|
}
|
|
|
|
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']);
|
|
|
|
|
|
if($file['EmailAttachment']['type'] == 'text/plain') {
|
|
$contents = nl2br($contents, true);
|
|
}
|
|
|
|
|
|
$this->set('contents', $contents);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|