我的index.html.twig中的搜索栏就像这样
<div id="main" class="search"> <p>Please insert the corresponding mail to find the S/MIME-Zertificat</p> <div class="form-container"> {% if smimekey == false %} <form action="{{path('search')}}" method="get"> <input type="text" class="email" name="sbar" placeholder="enter email ..." /> <input type="submit" value="search" class="submit"/> </form> {% elseif smimekey=="NULL" %} <form action="{{path('search')}}" method="get"> <input type="text" class="email" name="sbar" placeholder="No such Email or Zertifikat found" /> <input type="submit" value="search" class="submit"/> </form> {% elseif smimekey!="NULL" %} <form action="{{path('search')}}" method="get"> <input type="text" class="email" name="sbar" placeholder="enter email ..." /> <input type="submit" value="search" class="submit"/> ######### DOWNLOAD BUTTON / link ############### </form> {% endif %} </div> </div>
所以这个index.html.twig有3个可能的设计
我的php文件进入数据库并搜索看起来像这样的东西:
/**
* @Route("/search", name="search")
*/
public function searchAction(Request $request)
{
$sbar=$_GET['sbar'];
if (filter_var($sbar, FILTER_VALIDATE_EMAIL)) {
$smimekey = $this->getDoctrine()
->getRepository('AppBundle:Zertifikat')
->findOneByEmail($sbar);
$smimekey=stream_get_contents($smimekey->getSmimekey());
);
}
else{$smimekey="";}
if (!$smimekey) {
$smimekey="NULL";
}
return $this->render('default/index.html.twig', array(
'email'=>$sbar,'smimekey'=>$smimekey, 'base_dir' => realpath($this->container->getParameter('kernel.root_dir').'/..'),
));
}
所以现在我已经将smimekey保存为DB中的Blob现在是变量smimekey中的一个简单字符串,我将其返回到我的index.html.twig
我没有找到任何好的方法来下载&#34;生成的&#34;以我的变量作为内容的文件。
答案 0 :(得分:0)
/**
* @Route("/dw", name="dw")
*/
public function downloadAction(Request $request)
{
$sbar=$_GET['crt'];
if (filter_var($sbar, FILTER_VALIDATE_EMAIL)) {
$smimekey = $this->getDoctrine()
->getRepository('AppBundle:Zertifikat')
->findOneByEmail($sbar);
$email=$smimekey->getemail();
$smimekey=stream_get_contents($smimekey->getSmimekey());
$email=explode("@",$email);
}
else{$smimekey="";}
header('Content-Description: File Transfer');
header('Content-Type: application/x-x509-email-cert');
header('Content-Disposition: attachment; filename='.$email[0].".crt" );
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: 500');
ob_start();
echo $smimekey;
exit;
return $response;
}
这是我如何修复它我真的做了一个单独的动作下载Funktion