Symfony2 - 我应该把用户上传的文件放在哪里? [英] Symfony2 - Where should I put files uploaded by users?

查看:31
本文介绍了Symfony2 - 我应该把用户上传的文件放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Symfony 的新手,我将用户上传的图像放在 /web/bundles/mybundle/images/ 目录下.但我觉得这不是很好的做法.因为当我运行下面的命令以创建指向 src 目录下其他文件的符号链接时.用户上传的所有图片均已删除.

I am new with Symfony and I put images uploded by users under /web/bundles/mybundle/images/ directory. But I feel it's not good practice. Because when I run command below to create symlinks to other files under src directory. All images uploaded by users were removed.

php app/console assets:install ./web --symlink

我应该把用户上传的图片放在哪里?

Where should I put images uploaded by users?

推荐答案

我个人的解决方案是将它们放在 /app/data/uploads 目录中,然后:

My personal solution is to put them in the /app/data/uploads directory, and then either:

  1. 创建指向上传目录的符号链接,或
  2. 通过控制器提供上传服务

选项 1 可能是图像和资产的最佳选择,因为您希望它们尽快送达.但是,对于其他内容(PDF、文档等),选项 2 可能是您更好的选择,因为您可以更好地控制内容的提供方式.

Option 1 is probably your best bet for images and assets, as you want them served as quickly as possible. However, for other content (PDFs, Docs, etc), option 2 might be your better bet, as you have more control over how you want the content served.

我更喜欢保持我的 /web 目录尽可能干净,并将文件上传保持在公共范围之外(允许我更改提供文件的方法而无需移动它们 - IE从上面的选项 1 移动到选项 2),但如果您想将它们存储在 web 文件夹中,您可以按照 Symfony Cookbook 并将它们存储在类似 /web/uploads 的地方.

I prefer to keep my /web directory as clean as possible, and keep file uploads outside of public scope (allowing me to change my method of serving the files without needing to move them -- IE Moving from Option 1 above to Option 2), but if you want to store them in the web folder, you can follow the Symfony Cookbook and store them in something like /web/uploads.

这篇关于Symfony2 - 我应该把用户上传的文件放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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