【问题标题】:PHP cannot find my php files if not under htdocs folder如果不在 htdocs 文件夹下,PHP 找不到我的 php 文件
【发布时间】:2009-09-09 03:57:10
【问题描述】:

根据某人的建议,我已将所有 PHP 文件放在与 htdocs 相同级别的单独文件夹 (inc) 中。 htdocs 中只剩下 index.php。所以,是这样的:

C:\myproject\htdocs
- index.php

C:\myproject\inc
- login.php
- util.php
- register.php
...

现在,当我在浏览器中访问 localhost 时,index.php 已正确处理并显示。但是没有找到任何指向其他 php 文件的链接。我试图在链接前面加上“inc”,但仍然没有找到。我该怎么办?

我的 php.ini 文件有这一行(在 Windows 上):
include_path = ".;C:\myproject\inc"

【问题讨论】:

    标签: php apache configuration


    【解决方案1】:

    包含目录的意义在于放置您不希望被 Web 服务器访问的文件。如果 login.php 需要通过如下 URL 访问:

    http://yourdomain.com/login.php

    然后不要将 login.php 放在包含目录中。将 util.php 放在包含目录中是有意义的,因为您永远不希望这样:

    http://yourdomain.com/util.php

    【讨论】:

      【解决方案2】:

      您不能将网络可访问的文件放在 htdocs 文件夹之外,您应该将“inc”文件夹用于存放不应直接在浏览器中打开的“database_functions.inc”之类的文件:

      http://localhost/index.php // directly accessible - goes in htdocs
      http://localhost/login.php // directly accessible - goes in htdocs
      http://localhost/register.php // directly accessible - goes in htdocs
      
      http://localhost/util.php // you don't want people loading this file directly - put in 'inc'
      http://localhost/database_functions.php // you don't want people loading this file directly - put in 'inc'
      

      【讨论】:

        【解决方案3】:

        我相信你需要在你的 php.ini 中转义反斜杠——所以它应该是C:\\myproject\\inc。但正如其他人指出的那样,您将无法使用浏览器访问包含目录中的 PHP 文件,因为 Web 服务器不允许访问 htdocs 树之外的目录。

        【讨论】:

        • 我更喜欢使用斜杠,但双反斜杠也应该没问题(在 Windows 环境中)
        猜你喜欢
        • 2015-11-04
        • 2015-05-10
        • 2019-09-11
        • 1970-01-01
        • 2015-12-15
        • 2014-05-31
        • 2014-08-05
        • 1970-01-01
        • 2016-06-30
        相关资源
        最近更新 更多