Symfony2 : access files in folder outside web

戏子无情 提交于 2019-12-12 05:29:26

问题


I have a page in symfony2 with a java applet and javascript functions that make the java applet load files. These files are user-dependant and each file has to be stored in the user folder.

Users have their folder in a directory located at the root of the symfony folder (/temp/). Now i need the files in these folders to be available (like an asset?).

// Controler ( What i have now )
$filepath = $this->get('kernel')->getRootDir().'/../temp/'.$userfolder;

// View ( what i would like -using twig )
{% set path = userfolder ~ '/' ~ filename %}
<a href="javascript:document.jmol.script('load {{ asset(path) }}; frame all');">link</a>

回答1:


If your doc root is at the web directory, you cannot do what you are trying to do. This is the "root" directory which means you cannot access anything outisde it from the browser. This is a good thing, otherwise people browsing your site would be able to access other directories like your app security configuration, etc...

You have several options:

a) use a subdirectory of web to hold your user files, for example web/temp

b) hold them somewhere else and copy them to a web subfolder as needed. This is what symfony does for assets

c) create a new controller which intercepts routes like 'temp/{user}/{filename}' and then serves these files from the directory where you hold the files.



来源:https://stackoverflow.com/questions/12933993/symfony2-access-files-in-folder-outside-web

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!