本文整理匯總了PHP中Symfony\Component\HttpFoundation\BinaryFileResponse::setPublic方法的典型用法代碼示例。如果您正苦於以下問題:PHP BinaryFileResponse::setPublic方法的具體用法?PHP BinaryFileResponse::setPublic怎麽用?PHP BinaryFileResponse::setPublic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpFoundation\BinaryFileResponse
的用法示例。
在下文中一共展示了BinaryFileResponse::setPublic方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: function
return $app->render('home.html.twig');
});
$app->get('/tidus_laugh.{ext}', function ($ext) use($app) {
$sth = $app['db']->prepare('SELECT mime_type FROM extensions WHERE extension = ?');
$sth->bindValue(1, $ext, \PDO::PARAM_STR);
$sth->execute();
$mimeType = $sth->fetchColumn();
if (!is_string($mimeType)) {
$app->abort(404, 'No such extension');
}
$filename = __DIR__ . "/repository/tidus_laugh.{$ext}";
$expiresDate = new \DateTime();
$expiresDate->modify('+1 day');
$response = new BinaryFileResponse($filename);
$response->headers->set('Content-Type', $mimeType);
$response->setPublic();
$response->setExpires($expiresDate);
return $response;
})->assert('ext', '^[0-9a-z]+$');
$app->get('/manage', function () use($app) {
$extensions = $app['db']->fetchAll('SELECT * FROM extensions ORDER BY extension ASC');
return $app->render('manage.html.twig', ['extensions' => $extensions]);
});
$app->post('/new', function (Request $request) use($app) {
$extension = $request->request->get('extension');
$mimeType = $request->request->get('mime_type');
$password = $request->request->get('password');
foreach ([$extension, $mimeType, $password] as $input) {
if (!is_string($input) || !strlen($input)) {
$app->abort(403, 'Bad input');
}