本文整理匯總了PHP中Attachments::fileMimeType方法的典型用法代碼示例。如果您正苦於以下問題:PHP Attachments::fileMimeType方法的具體用法?PHP Attachments::fileMimeType怎麽用?PHP Attachments::fileMimeType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Attachments
的用法示例。
在下文中一共展示了Attachments::fileMimeType方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getAttachment
private function getAttachment()
{
// FIXME: Do we really need to mess with memory limits here? We're only reading ~80KB at a time...
@ini_set('memory_limit', '128M');
if (!$this->isRequiredIDValid('id', $_GET)) {
CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'No attachment ID specified.');
}
$attachmentID = $_GET['id'];
$attachments = new Attachments(-1);
$rs = $attachments->get($attachmentID, false);
if (empty($rs) || md5($rs['directoryName']) != $_GET['directoryNameHash']) {
CommonErrors::fatal(COMMONERROR_BADFIELDS, $this, 'Invalid id / directory / filename, or you do not have permission to access this attachment.');
}
$directoryName = $rs['directoryName'];
$fileName = $rs['storedFilename'];
$filePath = sprintf('attachments/%s/%s', $directoryName, $fileName);
/* Check for the existence of the backup. If it is gone, send the user to a page informing them to press back and generate the backup again. */
if ($rs['contentType'] == 'catsbackup' && !file_exists($filePath)) {
CommonErrors::fatal(COMMONERROR_FILENOTFOUND, $this, 'The specified backup file no longer exists. Please go back and regenerate the backup before downloading. We are sorry for the inconvenience.');
}
// FIXME: Stream file rather than redirect? (depends on download preparer working).
if (!eval(Hooks::get('ATTACHMENT_RETRIEVAL'))) {
return;
}
/* Determine MIME content type of the file. */
$contentType = Attachments::fileMimeType($fileName);
/* Open the file and verify that it is readable. */
$fp = @fopen($filePath, 'r');
if ($fp === false) {
CommonErrors::fatal(COMMONERROR_BADFIELDS, $this, 'This attachment is momentarily offline, please try again later. The support staff has been notified.');
}
/* Set headers for sending the file. */
header('Content-Disposition: inline; filename="' . $fileName . '"');
//Disposition attachment was default, but forces download.
header('Content-Type: ' . $contentType);
header('Content-Length: ' . filesize($filePath));
header('Pragma: no-cache');
header('Expires: 0');
/* Read the file in ATTACHMENT_BLOCK_SIZE-sized chunks from disk and
* output to the browser.
*/
while (!feof($fp)) {
print fread($fp, self::ATTACHMENT_BLOCK_SIZE);
}
fclose($fp);
/* Exit to prevent output after the attachment. */
exit;
}