0
我正在做一个文件浏览器应用与symfony 2.5和PHP 5.3.13。允许backslah url symfony2
这里我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>
。\。
我该如何解决此问题? 谢谢大家!
你可以试试$ dir_inter = rawurlencode($ dir_clients。'\\'。$ client。'\\ Interventions'); – zenith
$ dir_inter = rawurlencode(''。$ dir_clients。'\\'。$ client。'\\ Interventions'); var_dump($ dir_inter); => string'D%3A%2Fbla%2Fsvn-mtt-ppc%2Fbla%2Fsrc%2Fmain%2Fscripts%2Fapp%2F ..%2Fweb%2Fperformance-client%2F1.DonneesClient%5CAXA%5CInterventions'(length = 166) $ interv = scandir($ dir_inter); var_dump($ interv); =>布尔值FALSE –