2017-02-23 4 views
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 }}&nbsp;</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>

を生成していることである。\。

どうすればこの問題を解決できますか? ありがとうございます!

+0

$ dir_inter = rawurlencode($ dir_clients。 '\\'。$ client。 '\\ Intervention');を試すことができます。 – zenith

+0

$ 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 –

答えて

0

は最終的に私はそのようでした:「interventions_paramは」パラメータ

{% 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 %} 

としてconfig.ymlの「介入」として設定されている、それは安全でないですか?

関連する問題