EmailAttachment->findById($id); // Try legacy emails directory first (where vault saves files) $file_path = '/var/www/emails'; $full_path = $file_path."/".$file['EmailAttachment']['name']; // Fallback to attachments directory if not found in emails if(!file_exists($full_path)) { $file_path = Configure::read('attachments_directory'); $full_path = $file_path."/".$file['EmailAttachment']['name']; } if(file_exists($full_path)) { 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($full_path); exit(); } else { echo "ERROR: File Not Found"; echo '\n'; 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); // Try legacy emails directory first (where vault saves files) $file_path = '/var/www/emails'; $full_path = $file_path."/".$file['EmailAttachment']['name']; // Fallback to attachments directory if not found in emails if(!file_exists($full_path)) { $file_path = Configure::read('attachments_directory'); $full_path = $file_path."/".$file['EmailAttachment']['name']; } $contents = file_get_contents($full_path); if($file['EmailAttachment']['type'] == 'text/plain') { $contents = nl2br($contents, true); } $this->set('contents', $contents); } } }