0

I'm developing a system in which the codebase (php) is located in the /var/tmp/myapp/ directory in the server, although, I need to access/interact with it using an UI that can be accessible via browser. Is this possible, and how, or do O need to move the code inside the public_html directory - what I didn't really want.

Thank for any suggestions.

McRui
  • 1,879
  • 3
  • 20
  • 31
  • Just include it or load it from a file available in your web directory. – John Conde May 31 '14 at 21:13
  • If the web server can read it, you should be able to include it from code which does reside in public_html. However, unless you can modify Apache VirtualHost configurations you won't be able to point the web server directly at that directory. I would question why you would want active code residing in any `/tmp` directory though... – Michael Berkowski May 31 '14 at 21:14
  • Thanks @MichaelBerkowski and yes, that's also my question but the existing system is designed that way, and the code is there (and must be there...) and I need to access that code (controllers, models, etc) from a kind of web app that works as a console for that system. – McRui May 31 '14 at 21:22
  • 1
    @McRui As long as Apache can read it, you can include it then. You may wish to add it to your `include_path` http://us1.php.net/manual/en/function.set-include-path.php. – Michael Berkowski May 31 '14 at 21:28
  • Thanks @MichaelBerkowski , I didn't really knew that set_include_path php function. Looks like that's the solution for my question. Thank you very much. – McRui May 31 '14 at 21:35

1 Answers1

0

Thanks to @MichaelBerkowski's help, here's a simple tested snippet with the solution to the question.

<?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>";
?>
McRui
  • 1,879
  • 3
  • 20
  • 31