Я делаю приложение для проводника файлов с symfony 2.5 и Php 5.3.13.allow 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); => строка 'D% 3A% 2Fbla% 2Fsvn-mtt-ppc% 2Fbla% 2Fsrc% 2Fmain% 2Fscripts% 2Fapp% 2F ..% 2Fweb% 2Fperformance-client% 2F1.DonneesClients% 5CAXA% 5CInterventions' (длина = 166) $ interv = scandir ($ dir_inter); var_dump ($ interv); => boolean FALSE –