Forum Moderators: coopster

Message Too Old, No Replies

including files from elsewhere

including sub dir files etc

         

south

7:03 pm on Dec 4, 2003 (gmt 0)

10+ Year Member



Hello, this is my first post so take it easy :)

I'm trying to include a file from a sub directory images/thumbs.php however I've tried numerous ways and none seem to do it. I've already got an include statment on my index(layout) page as follows:
<code>
<?php

$valid_pages = array("main.php","photoshops.php","photoshops.php","aboutme.php","vinyl.php","vinylcollection.xml");
$page=$_GET['page'].".php";

if (isset($page) && is_file($page) && in_array($page,$valid_pages))
{
include($page);
}

else
{
include("main.php");
}

?>
</code>

then for my links on the index page I have the following:
<code>
<a href="index.php?page=aboutme">blah</a>
</code>
or similar...

I would be grateful of any help as this is starting to wind me up!

Cheers

jatar_k

7:06 pm on Dec 4, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld south,

am I correct in assuming that the code you posted is working but there is another include for thumbs.php that isn't? I don't see any reference to thumbs.php in the code.

it may just be a path problem try referEncing the file from the root. So if your images dir is located in the root dir.

include $_SERVER['DOCUMENT_ROOT'] . "/images/thumbs.php";

south

7:09 pm on Dec 4, 2003 (gmt 0)

10+ Year Member



Yea the code is working fine for my current includes (like the one I refrenced), I just can't figure how to adapt it so that I can include from other directories, I'll give that a try and let you know :)

south

7:12 pm on Dec 4, 2003 (gmt 0)

10+ Year Member



Sorry I'm a bit confused as to where to put

include $_SERVER['DOCUMENT_ROOT'] . "images/thumbs.php";

should I put this in my include statment or my link? Sorry for being so newbish!

jatar_k

7:34 pm on Dec 4, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ah, I might be understanding a little better now.

Did you want to add images/thumbs.php to the valid_pages array?

I am not 100% clear on what or where you are trying to include that page.

south

11:32 pm on Dec 4, 2003 (gmt 0)

10+ Year Member



Ok ill start fresh...

-I have a main/layout page called "index.php"
-Within this page all other pages are displayed (so I only need one layout page, css, etc)
-I have a page in the sub directory "photoshops" that I want to display called "thumbs.php"

Right, so I'm having trouble displaying thumbs.php and I'm not sure if this is because im not doing something right or because it's not added to the array or both. I hope this clears it up a bit?

jatar_k

11:56 pm on Dec 4, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if (isset($page) && is_file($page) && in_array($page,$valid_pages))

this portion makes sure, before it does the include statement, that
1. isset($page) - the variable $page is actually there
2. is_file($page) - that the value in the $page variable is an actual file on the site
3. in_array($page,$valid_pages) - is in the array of allowed filenames

so you should be able to add it to the array and it should work

$valid_pages = array("main.php","photoshops/thumbs.php", "photoshops.php", "aboutme.php", "vinyl.php", "vinylcollection.xml");

this is assuming that index.php is in the root of the site and that the photoshops directory is there as well.