PDA

View Full Version : Problem with php code. Please help!



spindrift
June 1st, 2006, 08:06 AM
Hello!

I'm using the following syntax to bring content into my websites' layout template:


<?php //check in the root folder first
if(file_exists('./' . $pagename . '.php'))
{
include './' . $pagename . '.php';
}
//if it wasn't found in the root folder then check in the news folder
elseif(file_exisits('./news/' . $filename . '.php'))
{
include './news/' . $pagename . '.php';
}
// if it couldn't be found display message
else
{
echo $pagename . '.php could not be found in either the root folder or the news folder!';
} ?>

What it's essentially saying is, if you can't find the .php file in the _root folder, look for it in the /news/ folder.

It works perfectly if loading something from the _root folder but I get an error if I need to bring something from the /news/ folder.

Can anyone see any potential problems with my code?

Thank you very much and I hope to hear from you.

Take care,

Mark

skOOb
June 1st, 2006, 08:40 AM
first error I saw belonged to the syntax devil...

elseif(file_exisits('./news/' . $filename . '.php'))

(should be exists)

JoshuaJonah
June 1st, 2006, 09:03 AM
Other than that, play with the targetting on the file, different versions of PHP combined with different versions of apache handle targetting differently.
So try:
"./news/folder"
"/news/folder"
"news/folder"
"./news/folder/"
"/news/folder/"
"news/folder/"
etc...
:mountie:

spindrift
June 1st, 2006, 09:13 AM
hi skOOb,

thanks for that - boy, do i look stupid!

i've corrected the typo but now everytime it tries to call something from the /news/ folder, it always come up with a message saying "060308.php could not be found in either the root folder or the news folder!".

i've checked that 060308.php is definately in /news/ so i don't understand it. Do you have any suggestions at all?

thanks again for all your help.

mark

skOOb
June 1st, 2006, 09:33 AM
I would do what Defective suggested...i have money that the last one ("news/".$filename.".php") will work. :beer:

bwh2
June 1st, 2006, 09:40 AM
try this:


<?php
$root = './'.$pagename.'.php';
$news = './news/'.$pagename.'.php';

if( file_exists($root) )
{
include( $root );
}

elseif( file_exists($news) )
{
include( $news );
}

else
{
echo 'Could not find files: <br />';
echo 'root: '.$root.'<br />';
echo 'news: '.$news;
}
?>

spindrift
June 1st, 2006, 12:40 PM
guys!

that is awesome, thank you so much - both those worked!

you're absolute legends, thank you!!!!!!

all the best and take care,

mark