array("%" . $_GET['photo'], 'String'), ); $dao = CRM_Core_DAO::executeQuery($sql, $params); while ($dao->fetch()) { $cid = $dao->id; } if ($cid) { $config = CRM_Core_Config::singleton(); $this->download( $config->customFileUploadDir . $_GET['photo'], 'image/' . pathinfo($_GET['photo'], PATHINFO_EXTENSION), $this->ttl ); CRM_Utils_System::civiExit(); } else { CRM_Core_Error::fatal('Photo does not exist'); } } /** * @param string $file * Local file path. * @param string $mimeType * @param int $ttl * Time to live (seconds). */ protected function download($file, $mimeType, $ttl) { if (!file_exists($file)) { header("HTTP/1.0 404 Not Found"); return; } elseif (!is_readable($file)) { header('HTTP/1.0 403 Forbidden'); return; } header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', CRM_Utils_Time::getTimeRaw() + $ttl)); header("Content-Type: $mimeType"); header("Content-Disposition: inline; filename=\"" . basename($file) . "\""); header("Cache-Control: max-age=$ttl, public"); header('Pragma: public'); readfile($file); } }