php中的文件系统vs url [关闭](file system vs url in php [closed])

编程入门 行业动态 更新时间:2024-10-23 21:35:10
php中的文件系统vs url [关闭](file system vs url in php [closed])

我已经构建了一个基于MVC架构的小型自定义框架,我有两个BASE_URL,类似于' http://example.com '和ROOT,就像'/ Applications / XAMPP / htdocs / WEBSITENAME /' 。 我试图获得一个普遍的共识,即当将其部署到服务器时哪个更好。 我确实有ssh访问它将被释放的服务器。 老实说,我不知道哪个是首选或为什么。 我做了很多谷歌搜索,发现相互矛盾的论点,所以我想我会问这里,因为我相信这个社区。 所以任何人都有关于哪个更好的想法,为什么?

哦,如果重要的是我们正在尝试使用httpd-vhost.conf来创建web目录而没有.htaccess文件,我们正在尝试删除所有mod_rewrite。 不确定这是否重要,但我想我会提供信息以防万一。

提前谢谢大家的帮助。

编辑**我想我还应该提到我并不是说我创建链接时,我的意思是包括css表,或js文件,或包括并要求其他php文件,这些类型的操作。

I have built a little custom framework that is based on MVC architecture and I have both BASE_URL which would be something like 'http://example.com' and ROOT which would be something like '/Applications/XAMPP/htdocs/WEBSITENAME/'. I am trying to get a general consensus as to which is better to use when this would be deployed to a server. I do have ssh access to the server that it would be released on. I just honestly do not know which is preferred or why. I did a lot of googling and found conflicting arguments so I thought I would ask here since I trust this community. So Anyone have thoughts on which is better and why?

Oh, if it matters we are trying to use httpd-vhost.conf to create the web directories and no .htaccess files, and we are trying to remove all mod_rewrite. Not sure if that matters, but I thought I would give the info just in case.

Thank you all for your help in advance.

EDIT** I guess I should also mention that I do not mean when I am creating links, I mean for including css sheets, or js files, or including and requiring other php files, those types of actions.

最满意答案

你有2个案例:

用于与服务器端的其他文件进行交互,而php脚本仍在执行 - 包括/要求其他php文件,开放资源等操作使用相对于ROOT的路径。

包括CSS,javascript,图像等 - 在客户端 - 你将使用BASE_URL。

例如,在PHP中:

require_once ROOT . DIRECTORY_SEPARATOR . 'my_configuration_file.php';

在HTML中:

<img src="<?=BASE_URL;?>/img/logo.png" alt="my company">

但考虑使用现有的PHP框架。 它将使您的生活更轻松,让您专注于您的产品/网站,而不是维护它。

You have 2 cases:

for interacting with other files on the sever's side, while the php script is still executing - operations like including / requiring other php files, fopen-ing resources and so on you use paths relative to your ROOT.

for including CSS, javascript, images and so on - on client side - you're going to use the BASE_URL.

For example, in PHP:

require_once ROOT . DIRECTORY_SEPARATOR . 'my_configuration_file.php';

in the HTML:

<img src="<?=BASE_URL;?>/img/logo.png" alt="my company">

But consider using an existing PHP framework. It will make your life easier and let you focus on your product / site rather than maintaing it.

更多推荐

本文发布于:2023-07-31 00:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340468.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件系统   url   php   closed   system

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!