Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 16th, 2004, 01:37 PM
Registered User
 
Join Date: Jul 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Including files across folders

I recently finished going through most of the chapters in WROX's Beginning Apache,PHP,MySQL and I'm now trying to integrate what I've learned into a functional CMS website.

My problem arises when I want to organize the huge number of files into various folders (CMS, authentification, gallery, other apps...). I use includes for my headers and footers which are housed in the root folder to generate all the interface pages, but images and other files don't show up because the file paths become invalid in the subfolders.

I must have missed this tip if it was in fact in the book. So how can I set the base address to the root folder so everything will work regardless of position in the folder setup? The PHP equiv to BASEHREF I suppose.

Many tx.
  #2 (permalink)  
Old July 16th, 2004, 01:42 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Not sure what you mean.

Perhaps something like this will work?

<?php
$basehref = "/some_folder/some_other_folder/";
function FILE($file_to_include)
{
 include $basehref . $file_to_include;
}
?>
some html.....
<?php
FILE("footer.php");
?>

Does this work?
HTH,

Snib

<><
  #3 (permalink)  
Old July 21st, 2004, 12:24 PM
Registered User
 
Join Date: Jul 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What this does it condense the amount of typing in the path of included files. My problem is somewhat different and since some programmers I've spoken to don't seem to understand my situation I will try to explain my objective better so I can get some ideas.

My root folder contains my index.php page, some layout includes (header.php, footer.php, etc.) and the standard connection/authentification files. It also contains a folder for images, one for scripts, and currently one for my CMS, which houses all the application files to keep pages organized and separated.

What I want to achieve is a stable graphical layout with changing content. Kind of what frames did for HTML by avoiding having the layout tables in each page of code. The only way I can think of doing this in PHP is by using header and footer includes to sandwich my application code. It's a little rough, but it's the best option I've got at the moment.

As I mentioned before, I'm including these pages in files contained in the root/ folder and in the root/cms/ folder. While the graphical (and links) work in the latter, they dont work in the former as the paths search for (example) "images/testpic.gif" although the images folder resides one level above the cms folder.

The short answer I'm looking for is how to resolve my particular issue. The long answer, is whether or not I'm approaching layout management correctly and what alternatives do I have?

Tx.

  #4 (permalink)  
Old July 26th, 2004, 04:17 PM
Registered User
 
Join Date: Jul 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Looking over a friend's code I discovered the potential solution to my include() nightmare.

Instead of including headers and footers into each application page, he has put the entire page layout in the index.php and used a switch statement (which grabs the variable from the URL) to generate the different pages. Basically...

INDEX.PHP

<?php
session_start();
include connection files
?>
<html> header, etc
...
<?php
switch inserts appropriate content page
?>
...
</html> footer

My problem now is that my CMS program pages use various includes and variable definitions before their respective headers are processed. By switch/including their output content as shown above I cant make the proper pre-header arrangements for each page, thus messing up the system.

Is my problem clear enough now? And can anyone suggest a solution to this or even an alternative? I'm a complete newbie, any help is welcome.


Similar Threads
Thread Thread Starter Forum Replies Last Post
including files above site root rinventive PHP How-To 2 August 29th, 2008 03:11 PM
connect to files from different folders lcyean ASP.NET 2.0 Basics 1 May 11th, 2007 07:23 AM
hide files/folders under window 98? Help me....!!! datphat Visual C++ 4 November 23rd, 2005 09:47 AM
correct way of including files. madhukp Classic ASP Basics 3 January 20th, 2005 09:39 AM
Including same files in different directories jeremy108 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 August 8th, 2003 01:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.