athanasius296
asked on
Function call to the file(s) in other directory
Hi,
While implementing the solution to my previous question (https://www.experts-exchange.com/questions/21127951/Getting-page-content-Function-calling.html),
I found out that I need to make a function call to the file(s) in other directory.
So, 2 questions:
1. If I have a function (see below), how to get the file stored in a directory different than one initiated by the function call?
Say, I have a file 'content_page1' stored in 'www/1/htdocs/a/b/c/d/e', and I make a function call from a file stored in 'www/1/htdocs/a'.
2. Is this path in 'include' is in a correct format?
Thanks!
Le
<HTML>
<BODY>
<!-- Function getContent -->
<?php
include '/www/1/htdocs/myfuncs.inc .php'; <----Correct?
?>
<!-- CONTENT -->
<?php getContent(); ?>
</BODY>
</HTML>
myfuncs.php:
<?php
function getContent() {
if (empty($_GET['page'])) {
$page = 'content_page1';
} else {
$page = $_GET['page'];
}
$page .= '.php';
if (false == is_file($page)) {
$page = 'file_not_found.php';
}
include($page);
}
While implementing the solution to my previous question (https://www.experts-exchange.com/questions/21127951/Getting-page-content-Function-calling.html),
I found out that I need to make a function call to the file(s) in other directory.
So, 2 questions:
1. If I have a function (see below), how to get the file stored in a directory different than one initiated by the function call?
Say, I have a file 'content_page1' stored in 'www/1/htdocs/a/b/c/d/e', and I make a function call from a file stored in 'www/1/htdocs/a'.
2. Is this path in 'include' is in a correct format?
Thanks!
Le
<HTML>
<BODY>
<!-- Function getContent -->
<?php
include '/www/1/htdocs/myfuncs.inc
?>
<!-- CONTENT -->
<?php getContent(); ?>
</BODY>
</HTML>
myfuncs.php:
<?php
function getContent() {
if (empty($_GET['page'])) {
$page = 'content_page1';
} else {
$page = $_GET['page'];
}
$page .= '.php';
if (false == is_file($page)) {
$page = 'file_not_found.php';
}
include($page);
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.