Web应用程序访问public_html之外的代码

时间:2014-05-31 21:11:45

标签: php .htaccess public-html

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

感谢您的任何建议。

1 个答案:

答案 0 :(得分: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>";
?>