<?php
class EmailAttachmentsController extends AppController {

    var $name = 'EmailAttachments';
    var $helpers = array('Html', 'Form');


    function download($id) {

        $file = $this->EmailAttachment->findById($id);
        if(file_exists($file['EmailAttachment']['filename'])) {



        Configure::write('debug', 0);
        
        header('Content-type: ' . $file['EmailAttachment']['type']);
        header('Content-length: ' . $file['EmailAttachment']['size']);
        header('Content-Disposition: attachment; filename='.$file['EmailAttachment']['name']);
       
     //   ob_clean();
      //  flush();
        readfile($file['EmailAttachment']['filename']);
        //  echo $file['EmailAttachment']['filename']
        exit();
        }
        else {
            echo "ERROR!! : File Not Found";
            echo $file['EmailAttachment']['filename'];
        }
    }

}
