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。 '\\ Intervention');を試すことができます。 – zenith
$ dir_inter = rawurlencode( ''。$ dir_clients。 '\\'。$ client。 '\\介入'); var_dump($ dir_inter); =>文字列 'D%3A%2Fbla%2Fsvn-mtt-ppc%2Fbla%2Fsrc%2Fmain%2Fscripts%2Fapp%2F ..%2Fweb%2Fperformance-client%2F1.DonneesClients%5CAXA%5CInterventions(length = 166) $ interv = scandir($ dir_inter); var_dump($ interv); =>ブール値FALSE –