本文整理汇总了PHP中Symfony\Component\HttpFoundation\BinaryFileResponse::setPrivate方法的典型用法代码示例。如果您正苦于以下问题:PHP BinaryFileResponse::setPrivate方法的具体用法?PHP BinaryFileResponse::setPrivate怎么用?PHP BinaryFileResponse::setPrivate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\BinaryFileResponse
的用法示例。
在下文中一共展示了BinaryFileResponse::setPrivate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deliverFile
/**
* {@inheritdoc}
*/
public function deliverFile($file, $filename = '', $disposition = self::DISPOSITION_INLINE, $mimeType = null, $cacheDuration = 0)
{
$response = new BinaryFileResponse($file);
$response->setContentDisposition($disposition, $this->sanitizeFilename($filename), $this->sanitizeFilenameFallback($filename));
$response->setMaxAge($cacheDuration);
$response->setPrivate();
if (null !== $mimeType) {
$response->headers->set('Content-Type', $mimeType);
}
return $response;
}
示例2: handleServeIconRequest
/**
* Handle request to /serve-icon handler
*
* @param bool $allow_removing_headers Alter PHP's global headers to allow caching
* @return BinaryFileResponse
*/
public function handleServeIconRequest($allow_removing_headers = true)
{
$response = new Response();
$response->setExpires($this->getCurrentTime('-1 day'));
$response->prepare($this->request);
if ($allow_removing_headers) {
// clear cache-boosting headers set by PHP session
header_remove('Cache-Control');
header_remove('Pragma');
header_remove('Expires');
}
$path = implode('/', $this->request->getUrlSegments());
if (!preg_match('~serve-icon/(\\d+)/(.*+)$~', $path, $m)) {
return $response->setStatusCode(400)->setContent('Malformatted request URL');
}
list(, $guid, $size) = $m;
$entity = $this->entities->get($guid);
if (!$entity instanceof \ElggEntity) {
return $response->setStatusCode(404)->setContent('Item does not exist');
}
$thumbnail = $entity->getIcon($size);
if (!$thumbnail->exists()) {
return $response->setStatusCode(404)->setContent('Icon does not exist');
}
$if_none_match = $this->request->headers->get('if_none_match');
if (!empty($if_none_match)) {
// strip mod_deflate suffixes
$this->request->headers->set('if_none_match', str_replace('-gzip', '', $if_none_match));
}
$filenameonfilestore = $thumbnail->getFilenameOnFilestore();
$last_updated = filemtime($filenameonfilestore);
$etag = '"' . $last_updated . '"';
$response->setPrivate()->setEtag($etag)->setExpires($this->getCurrentTime('+1 day'))->setMaxAge(86400);
if ($response->isNotModified($this->request)) {
return $response;
}
$headers = ['Content-Type' => (new MimeTypeDetector())->getType($filenameonfilestore)];
$response = new BinaryFileResponse($filenameonfilestore, 200, $headers, false, 'inline');
$response->prepare($this->request);
$response->setPrivate()->setEtag($etag)->setExpires($this->getCurrentTime('+1 day'))->setMaxAge(86400);
return $response;
}