目录结构:将应用程序与上传的文件分开
我有一个与应用程序目录结构有关的一般问题。我有我的应用程序和定期更新的 git 存储库上所需的所有文件(PHP 文件、CSS、JS 等)。我有一个上传文件夹,用于存储用户上传的头像和文件。
例如,是否有惯例将应用程序的这两部分分开?:
public_html
/app
/uploads
或者目录结构应该看起来更像这样吗?:
public_html
/index.php
/css
/js
/uploads
当我合并来自 github 的更改时,我不这样做希望我的任何用户的文件受到影响。
- 那么应用程序应该与上传内容在物理上分开,还是应该将
/uploads
包含到 .gitignore 中? - 如果需要重写 .htaccess 该怎么办?
I have a general question to do with application directory structure. I have my application and all the files required on a git repo that is regularly updated (PHP files, CSS, JS etc). And I have an uploads folder where users' uploaded avatars and files get stored.
Is it convention to separate these two parts of the app for example?:
public_html
/app
/uploads
or should the directory structure look more like this?:
public_html
/index.php
/css
/js
/uploads
When I merge changes from github I don't want any of my users' files to be affected.
- So should the app be physically separated from the uploads or should I just include
/uploads
to .gitignore? - What if any .htaccess rewrites are required?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这两种结构都很好——这取决于你。只要上传位于单独的文件夹中,您就可以将其从版本控制中排除,应该没问题。您的 .htaccess 也可以位于版本控制系统中。
I think both structures are fine -- it's up to you. As long as the uploads are in a seperate folder, you can exclude that from versioning and you should be fine. Your .htaccess can be in the versioning system as well.
我宁愿使用第二个选项,如果上传不被不同的应用程序共享,它们应该是应用程序的一部分,所以我将它放在应用程序的目录中,并将其包含在 .gitignore 中。
我想这两种方法都很好。但对我来说,应用程序结构应该是这样的,不是所有东西都应该放在公共目录中,只有用户需要访问的东西(服务器独占文件应该受到用户保护)
类,conf,上传,...只能由服务器访问
I'd rather use the second option, if the uploads are not shared by different apps they should be part of the app so I would place it inside app's directory, and include it in .gitignore.
Both approaches are fine I guess. But for me the app structure should be like this, not everything should go in the public directory, only the things that need to be accessed by the user (server exclusive files should be protected from users)
class, conf, upload, ... should only be accessed by the server