Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Function call to the file(s) in other directory

Posted on 2004-09-12
2
Medium Priority
?
250 Views
Last Modified: 2010-08-05
Hi,
While implementing the solution to my previous question (http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_21127951.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);
    }
0
Comment
Question by:athanasius296
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Assisted Solution

by:aib_42
aib_42 earned 200 total points
ID: 12041075
> include '/www/1/htdocs/myfuncs.inc.php'; <----Correct?

This means that you have a "www" directory in your directory root (ie /www for *nix or c:\www for windows)
And that has a subdirectory called "1", that has one called "htdocs", etc... It looks correct to me.

The thing to be careful about is giving the file's true path on the server filesystem, not the web server. (ie not "www.mysite.com/somedir/something.php" or "/somedir/something.php".

I do not understand your first question very well, but this might answer it:
include()'ing a file is, effectively, copying all the lines in the file being included, and pasting them right on the line with the include() call.
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 300 total points
ID: 12041584
Yes you can inculde pages in other directories. For that use a switch as pointed out in the other question.:

      switch ($_GET['page']) {
          case("content_page2"):
               $page = 'b/c/d/content_page2.php';
          case("content_page3"):
               $page = 'b/c/content_page3.php';
          default:
               $page = 'content_page1.php';
      }
        if (false == is_file($page)) {
            $page = 'file_not_found.php';
        }
        include($page);

So you can easyly configure where the included files should come from.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question