本文整理汇总了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;
}