本文整理匯總了PHP中Symfony\Component\HttpFoundation\BinaryFileResponse::setLastModified方法的典型用法代碼示例。如果您正苦於以下問題:PHP BinaryFileResponse::setLastModified方法的具體用法?PHP BinaryFileResponse::setLastModified怎麽用?PHP BinaryFileResponse::setLastModified使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpFoundation\BinaryFileResponse
的用法示例。
在下文中一共展示了BinaryFileResponse::setLastModified方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getAction
/**
* Get resource
*
* @param Request $request
* @param string $id
*
* @return BinaryFileResponse
*/
public function getAction(Request $request, $id)
{
$realId = $request->getSession()->get('_resource/' . $id);
$class = $this->getParameter('rafrsr_resource.config')['class'];
$resource = null;
if ($class && $realId) {
$resource = $this->getDoctrine()->getRepository($class)->find($realId);
}
if (!$resource) {
throw new NotFoundHttpException();
}
// Generate response
$response = new BinaryFileResponse($resource->getFile()->getRealPath());
$response->setLastModified($resource->getUpdated());
return $response;
}
示例2: serveFile
protected function serveFile($filename, $displayName, Request $request, $asAttachment = false)
{
$lastModified = new \DateTime();
$lastModified->setTimestamp(filemtime($filename));
$ifModifiedSince = $request->headers->has('If-Modified-Since') ? new \DateTime($request->headers->get('If-Modified-Since')) : false;
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimeType = finfo_file($finfo, $filename);
$response = new BinaryFileResponse($filename);
$response->setMaxAge(10);
$response->headers->addCacheControlDirective('must-revalidate');
$response->headers->set('Content-Type', $mimeType);
$response->setLastModified($lastModified);
$response->setContentDisposition($asAttachment ? ResponseHeaderBag::DISPOSITION_ATTACHMENT : ResponseHeaderBag::DISPOSITION_INLINE, $displayName, mb_convert_encoding($displayName, "ASCII", "UTF-8"));
$response->prepare($request);
if ($ifModifiedSince && $ifModifiedSince <= $lastModified) {
$response->setStatusCode(304);
}
return $response;
}