【问题标题】:Web app accessing code outside public_htmlWeb 应用程序访问 public_html 之外的代码
【发布时间】:2014-05-31 21:11:44
【问题描述】:

我正在开发一个系统,其中代码库 (php) 位于服务器的 /var/tmp/myapp/ 目录中,但我需要使用可通过以下方式访问的 UI 访问/交互它浏览器。这是否可能,以及 O 需要如何或是否需要将代码移动到 public_html 目录中 - 这是我真正不想要的。

感谢您的任何建议。

【问题讨论】:

  • 只需包含它或从您的网络目录中可用的文件中加载它。
  • 如果网络服务器可以读取它,您应该能够从驻留在 public_html 中的代码中包含它。但是,除非您可以修改 Apache VirtualHost 配置,否则您将无法将 Web 服务器直接指向该目录。我会质疑为什么您希望活动代码驻留在任何 /tmp 目录中...
  • 谢谢@MichaelBerkowski,是的,这也是我的问题,但现有系统就是这样设计的,代码就在那里(而且必须在那里......),我需要访问该代码(控制器、模型等)来自一种网络应用程序,该应用程序用作该系统的控制台。
  • @McRui 只要 Apache 可以读取,你就可以包含它。您不妨将其添加到您的include_pathus1.php.net/manual/en/function.set-include-path.php
  • 谢谢@MichaelBerkowski,我真的不知道 set_include_path php 函数。看起来这就是我的问题的解决方案。非常感谢。

标签: php .htaccess public-html


【解决方案1】:

感谢@MichaelBerkowski 的帮助,这里有一个简单的测试sn-p 以及问题的解决方案。

<?php
/**
 * Include code base from outside public_html to be accessible to scripts
 * that are accessible via web browser
 */ 

// defines the path of the codebase
define("APPLICATION_PATH", realpath('/usr/apps/myapp/controllers/'));

// defines the working directory of the, i.e., index.php file
define("CURRENT_PATH", getcwd());

// create the paths array
$paths = array(APPLICATION_PATH, CURRENT_PATH);

// set the include path configuration option for the duration of the script
set_include_path(implode($paths, PATH_SEPARATOR));

// include a script file located in the realpath
include('ReporterClass.php'); // located in /usr/apps/myapp/

// instantiate the class
$report = new Reporter();

// test output
echo "<h3>".$report->showReport("Sample Report")."</h3>";
?>

【讨论】:

    猜你喜欢
    • 2013-01-18
    • 2014-05-12
    • 1970-01-01
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    • 2014-06-04
    • 2021-07-14
    相关资源
    最近更新 更多