<?php $query = new Model_Download_File(); $query->where('encodedtitle = ?', pathinfo(Typeframe::CurrentPage()->pathInfo(), PATHINFO_FILENAME)); $query->where('siteid = ?', Typeframe::CurrentPage()->siteid()); $download = $query->getFirst(); if ($download->exists()) { $fullname = TYPEF_DIR . '/files/public/downloads/' . $download['filename']; $extension = pathinfo($download['filename'], PATHINFO_EXTENSION); if (file_exists($fullname) && is_file($fullname)) { $download['downloads'] = $download['downloads'] + 1; $download->save(); header('Pragma: public'); header('Content-Type: application/force-download'); header('Content-Disposition: attachment; filename="' . $download['encodedtitle'] . '.' . $extension . '"'); readfile($fullname); exit; } } http_response_code(404); Typeframe::SetPageTemplate('/404.html');