我正在使用 symfony 2.5 和 Php 5.3.13 制作一个文件浏览器应用程序。
这里是我的 scanAction,列出了目录的文件:
public function listAction($client)
{
$dir_clients = $this->container->getParameter('dir_clients');
$dir_inter = ''.$dir_clients.'\\'.$client.'\\Interventions';
$interv = scandir($dir_inter);
$interv = array_slice($interv, 2);
$to_remove = array('Thumbs.db');
$interv_list = array_diff($interv, $to_remove);
return $this->render('MyBundle:Default:pilotage.html.twig', array(
// Here 'liste' = array of files in 'dir_interventions'
// 'dir_interventions' is a string of the directory
'liste' => $interv_list,
'dir_interventions' => $dir_inter,
));
}
这是我的pilotage.html.twig:
{% for files in liste %}
<div style="text-align:left";>
<a target="" href="{{ path('affiche_pilotage', { 'repertoire':dir_interventions, 'file':files }) }}">{{ files }} </a>
</div>
{% endfor %}
我的 Affiche_pilotage 路径:
affiche_pilotage:
pattern: /pilotage/{repertoire}/file}
defaults: { _controller: MyBundle:Default:affichePilotage}
requirements:
repertoire: .+
file: .+
最后是我的 affichePilotageAction();
public function affichePilotageAction( $repertoire , $file )
{
$response = new Response();
$response->setContent(file_get_contents(''.$repertoire.'/'.$file.''));
$response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$response->headers->set('Content-disposition', 'filename='. $file);
return $response;
}
我的问题是生成的
<a href=':D/svn/blabla/blabla/web\client\Interventions/filename'</a>
因为反斜杠.\.
我该如何解决这个问题? 谢谢大家!
最后我确实这样做了:“interventions_param”在 config.yml 中设置为“Interventions”作为参数
{% for files in liste %}
{% set repertoire = dir_client ~ '/' ~ client ~ '/' ~ interventions_param %}
<div style="text-align:left";>
<li><a target="" href="{{ path('affiche_excel', { 'repertoire':repertoire, 'file':files }) }}">{{ files }}</a></li>
</div>
{% endfor %}
不安全吗?