0

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

感谢您的任何建议。

4

1 回答 1

0

感谢@MichaelBerkowski 的帮助,这里有一个简单的测试片段,其中包含问题的解决方案。

<?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>";
?>
于 2014-05-31T23:00:05.517 回答