function download_old($id) { $result = $this->FileLibraryFile->findById($id); if (empty($result)) { $this->_smartFlash('Sorry, that file was not found.', '/'); } elseif ($result['FileLibraryFile']['user_id'] != $this->Auth->user('id') && $this->Auth->user('administrator') != true) { $this->_smartFlash('Sorry, you don\'t have permission to download that file.', '/'); } else { $filepath = WWW_ROOT . 'files' . DS . $result['FileLibraryFile']['id'] . DS . $result['FileLibraryFile']['filename']; if (file_exists($filepath)) { // MimeType class distributed with Attachments Behaviour App::import('Vendor', 'Mimetype'); header('Content-type: ' . Mimetype::detectFast($filepath)); header('Content-Disposition: attachment; filename="' . $result['FileLibraryFile']['filename'] . '"'); readfile($filepath); exit; } else { $this->_smartFlash('Sorry, that file was not found.', '/'); } } }