Forum Moderators: coopster
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
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";
-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?
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.