}
$attachmentId = (int) ltrim($attachment, " 0\t\n\r");
$attachmentObj = new Attachment($attachmentId);
if (!$attachmentObj->exists()) {
header('HTTP/1.0 404 Not Found');
echo 'Error 404: File not found';
exit;
}
header('Content-Type: ' . $attachmentObj->getMimeType());
if ($g_download == 1) {
header('Content-Disposition: ' . $attachmentObj->getContentDisposition() . '; filename="' . $attachmentObj->getFileName()) . '"';
} else {
if ($g_show_in_browser == 1) {
header('Content-Disposition: inline; filename="' . $attachmentObj->getFileName()) . '"';
} else {
if (!$attachmentObj->getContentDisposition() && strstr($attachmentObj->getMimeType(), 'image/') && (strstr($_SERVER['HTTP_ACCEPT'], $attachmentObj->getMimeType()) || strstr($_SERVER['HTTP_ACCEPT'], '*/*'))) {
header('Content-Disposition: inline; filename="' . $attachmentObj->getFileName()) . '"';
} else {
header('Content-Disposition: ' . $attachmentObj->getContentDisposition() . '; filename="' . $attachmentObj->getFileName()) . '"';
}
}
}
header('Content-Length: ' . $attachmentObj->getSizeInBytes());
$filePath = $attachmentObj->getStorageLocation();
if (file_exists($filePath)) {
readfile($filePath);
} else {
header('HTTP/1.0 404 Not Found');
echo 'Error 404: File not found';
exit;
}