Symfony2:访问网络外文件夹中的文件 [英] Symfony2 : access files in folder outside web

查看:27
本文介绍了Symfony2:访问网络外文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 symfony2 中有一个页面,其中有一个 java 小程序和 javascript 函数,这些函数使 java 小程序加载文件.这些文件取决于用户,每个文件都必须存储在用户文件夹中.

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.

用户的文件夹位于 symfony 文件夹 (/temp/) 的根目录中.现在我需要这些文件夹中的文件可用(比如资产?).

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>

推荐答案

如果您的文档根目录位于 Web 目录中,您将无法执行您想要执行的操作.这是根"目录,这意味着您无法从浏览器访问它之外的任何内容.这是一件好事,否则浏览您网站的人将能够访问其他目录,例如您的应用安全配置等...

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...

您有多种选择:

a) 使用 web 的子目录来保存您的用户文件,例如 web/temp

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

b) 将它们放在其他地方,并根据需要将它们复制到网络子文件夹中.这就是 symfony 为资产所做的

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

c) 创建一个新的控制器,它拦截诸如temp/{user}/{filename}"之类的路由,然后从您保存文件的目录中提供这些文件.

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.

这篇关于Symfony2:访问网络外文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆