Jump to content


Photo

How can I ask my php include to search 2 folders for content?


  • Please log in to reply
4 replies to this topic

#1 spindrift

spindrift
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 29 May 2006 - 04:39 PM

Hi guys,

I'm using the below code to call content into my websites' layout:

<?php @ require_once ("$pagename.php"); ?>

At the moment, I believe it will only search for files in the same folder as my main template which is fine.

The thing is though, is that I want to put all the news files in a folder called 'news'. Is there a way that this code can be edited so it can not only search for and include files in the same folder but also news/ ?

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

All the best,

Mark

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 29 May 2006 - 05:18 PM

You can check whether a file exists using this -[a href=\"http://ca3.php.net/manual/en/function.file-exists.php\" target=\"_blank\"]php.net/manual/en/function.file-exists.php[/a]. That would let you test for the existence of a file that might be in either location, and only include it when you find it (and from where).
Legend has it that reading the manual never killed anyone.
My site

#3 spindrift

spindrift
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 29 May 2006 - 05:39 PM

hi andyb,

many thanks for the reply.

ill be honest and say i'm new to php and don't really understand all the code in the manual - let alone how to edit it for my needs!

is there a simpler way where the script i posted can search in the news folder? if so, could i be a pain and ask if you would mind telling me the code i need please?

thank you very much once again and i hope to hear from you.

mark


#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 29 May 2006 - 06:22 PM

'Search' isn't what you want then? All you need is to include it from a different folder if it exists.
<?php 
$the_page = "news/". $pagename. ".php";
@include($the_page); ?>

Legend has it that reading the manual never killed anyone.
My site

#5 spindrift

spindrift
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 29 May 2006 - 07:10 PM

hi andy,

thanks for that and for getting back to me...

i put the code in my template file next to
<?php @ require_once ("$pagename.php"); ?>
but it didn't work.

basically what i am after is <?php @ require_once ("$pagename.php" or news/$pagename.php); ?> but i wouldn't know how to write it properly. do you know how it should be written properly?

thank you very much for everything.

all the best,

mark




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users