本文介绍了如何获得“应用程序根目录"我的网址来自PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的URL是http://www.server.com/myapp/stuff/to/see,并且磁盘上的目录结构是htdocs/myapp/*,如何提取/myapp部分?另外,如果没有应用程序文件夹并且应用程序根目录只是"/"怎么办?是否有预定义的变量来获取该值?

If my URL is http://www.server.com/myapp/stuff/to/see and my directory structure on disk is htdocs/myapp/*, how can I extract the /myapp part? Also, what if there was no application folder and the application root was just '/'? Is there a predefined variable for getting that value?

我想要的是一个能够从请求URI中修剪/myapp的函数,这样我只剩下/stuff/to/see.并且,如果我要将应用程序移动到服务器文档的根目录,也要确定它(以便/stuff/to/see刚作为/stuff/to/see返回)

What I want is a function that is able to trim /myapp off of the request URI, so that I'm only left with /stuff/to/see. AND, if I were to move the application to the server document root, have it determine that as well (so that /stuff/to/see is just returned as /stuff/to/see)

我的目录结构是这样:

application
  |-config
    |-config.inc.php
library
  |-autoload.class.php
public
  |-css
  |-img
index.php

因此,从index.php,我想知道如何获得我上面的要求.

So, from index.php, I want to know how to get what I asked above.

推荐答案

对于 web根,有多个答案中指出的DOCUMENT_ROOT.对于应用程序根,系统无法确定应用程序中的哪个文件夹是根文件夹.您将必须手动设置.

For the web root, there is DOCUMENT_ROOT as pointed out in several answers. For the application root, there is no way for the system to tell which folder in your application is the root folder. You will have to set that manually.

大多数应用程序使用dirname(__FILE__);或配置设置定义应用程序根目录,并将其存储在整个应用程序中可用的常量中.

Most applications define an application root using dirname(__FILE__); or a config setting and store that in a constant that is available throughout the application.

这篇关于如何获得“应用程序根目录"我的网址来自PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:37