Jump to content

help with paths to include files


newbie69

Recommended Posts

 

I have site that uses a include file for its pages. Recently i had to create a folder with different pages, but had to create the a include file with the same code but specifically for the those files that are in a directory. If i a create another directory in that directory, it means i have to create another include file specifically for files at that level.

 

Is there a way for me to eliminate this problem. Creating the include files with the same code for different folders is going to become very unmanagable.

 

files structure

 

/ _images

 

/php_scripts

 

    -getscv_root_level.incl

    -getscv_level2.incl

 

/newsletters

 

    /august

    -index.php

 

-index.php

-training_register.php

 

 

please note that the include files are the sames except for the way they are point to different direcoty levels.

 

pages in the root level would refer to getscv_root_level.incl

 

snippet of code for getscv_root_level.incl:

 

----------

 

echo "<td class=\"content bordersolid\">".($Entry[2] == "" ? " " : "<a href=\"".$Entry[4]."\" title=\"".$Entry[2]."\" target=\"\">".$Entry[2]."</a>")."</td>";

$temp = "training_register.php?course=".$Entry[2]."&d=".$Entry['DisplayDate'];

echo "<td class=\"content bordersolid\"><a href=\"".$temp."\" id=\"imglink\" title=\"\">

<img src=\"_images/home_register_button.gif\" border=\"0\"></td>

</a>";

 

----------------

pages in the root level would refer to -getscv_level2.incl

snippet of code for getscv_level2.incl:

 

-------------

 

echo "<td class=\"content bordersolid\">".($Entry[2] == "" ? " " : "<a href=\"../../".$Entry[4]."\" title=\"".$Entry[2]."\" target=\"\">".$Entry[2]."</a>")."</td>";

$temp = "training_register.php?course=".$Entry[2]."&d=".$Entry['DisplayDate'];

echo "<td class=\"content bordersolid\"><a href=\"../../$temp\" id=\"imglink\" title=\"\">

<img src=\"../../_images/home_register_button.gif\" border=\"0\"></td>

</a>";

 

-----------

 

 

I hope this is more decriptive

 

the only difference between the 2 snippets are "../../"

 

 

I ideally i would only like to point to the one file regards of where in the website (be it at root level or nested directories) the calling page is located.

 

Thanks

Link to comment
Share on other sites

Hi

 

This is the statement i used:

 

include($_SERVER['DOCUMENT_ROOT']."php_scripts/global.inc");

 

this works fine for documents in root level, but if i try this for pages in that are in another folder, it doenst.

 

Is there something i'm doing wrong?

 

Thanks

Link to comment
Share on other sites

Your missing a slash.

 

include $_SERVER['DOCUMENT_ROOT'] . "/php_scripts/global.inc";

 

ps: Using the inc file extension is a bad idea, as if someone stubles accross this file they may be able to view it in plain text. No good if youve got passwords and other sensitive data in it.

Link to comment
Share on other sites

Hi jeetesh,

 

I have tried your piece of code and i'm get the a "wrong path" on the screen.

 

 

don't know if this clarifies things

 

site:

 

/php_scripts/global.php

 

/newsletters

    /august

    index.php

 

 

I used include($_SERVER['DOCUMENT_ROOT']."/project_folder/includes/file1.inc"; on newsletters/august/index.php

 

if i use include($_SERVER['DOCUMENT_ROOT']."../../project_folder/includes/file1.inc"); then it works, but this what i want to avoid.

 

Thanks

 

Sudhir

Link to comment
Share on other sites

Generate Stucture like this

 

C:/Program Files/Apache Group/Apache2/htdocs/MY_PROJECT/php_scripts/global.php

 

C:/Program Files/Apache Group/Apache2/htdocs/MY_PROJECT/newsletters/august/index.php

 

 

Here MY_PROJECT is current project's root directory.

 

i mean php_scripts,newsletters are in a common directory.

 

include($_SERVER['DOCUMENT_ROOT']."MY_PROJECT/php_scripts/global.php");

Link to comment
Share on other sites

would anyone know why does not this work on my pc?

 

My php is working off the IIS on windows. When i try this on my online site it works and returns :"/home/optinumi/public_html"

 

on my desktop PC it doesnt.

 

<?php

 

$test= $_SERVER['DOCUMENT_ROOT'];

// this returns a blank.

echo $test;

?>

Link to comment
Share on other sites

Hi,

 

 

since i want all my files,regardless of where they are in the site to use the same include file, which contains links

i did the following

 

this is what i had in the include file:

echo "<a href=../../events.php">dafdasf</a>";

 

this is what i tried to do:

Since i want the links to work across the entire site regardless of how many folders i put the file in, i tried the following and when i click on the link it doesnt work.

 

 

echo "<a href=".$_SERVER['DOCUMENT_ROOT']."/events.php>events</A>";

 

when i echo $_SERVER['DOCUMENT_ROOT'] i get the following response

 

C:\pws\optinum

 

 

and my events.php is located at c:\pws\optinum\events.php so i dont see why my piece of code shouldnt work?

 

does anyone know something i dont?

 

thanks

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.