MyBB Community Forums

Full Version: PHP Include's
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
Help, I nub. Smile

I need a simpler way of doing my PHP includes, instead of the way I currently link to the pages.
(For example:
<?php
include '/home/dalton/public_html/etc/etc/etc/etc/too/many/etcs'; ?>

I read that there's a way to do it by doing something like ././ or ../../ i can't remember which. Anyway, I just need a simpler way of doing it, kinda like the ./

So.. suggestions? Answers?
Smile
Try doing:
$dir = dirname(__FILE__);
and then:
$folder = $dir.'folder/blah/lol/omggz/rofl/';
echo $folder;

and tell me what you get.
Err remember to use / after $dir, it does not append it. Also you do not have to use absolute path, you might use include "./include/some.class.php"; . Although it's the prefered way to use dirname to get the absolute path.
Sorry

I Cant Get
(2009-03-18, 08:35 PM)Tom Loveric Wrote: [ -> ]Try doing:
$dir = dirname(__FILE__);
and then:
$folder = $dir.'folder/blah/lol/omggz/rofl/';
echo $folder;

and tell me what you get.

Sorry, but where does that go?

(2009-03-18, 09:19 PM)remshad Wrote: [ -> ]Sorry

I Cant Get

SERIOUSLY. Stop posting randomly.
(2009-03-18, 09:19 PM)remshad Wrote: [ -> ]Sorry

I Cant Get
Rolleyes Will you please stop posting randomly?? Post count is ONLY a number!

(2009-03-18, 10:42 PM)Dalton Wrote: [ -> ]
(2009-03-18, 08:35 PM)Tom Loveric Wrote: [ -> ]Try doing:
$dir = dirname(__FILE__);
and then:
$folder = $dir.'folder/blah/lol/omggz/rofl/';
echo $folder;

and tell me what you get.

Sorry, but where does that go?
Just put it in a new .php file, just for testing sake.
So the file should look like:
<?php
$dir = dirname(__FILE__);
$folder = $dir.'folder/blah/lol/omggz/rofl/';
echo $folder;
?>

?
Actually, try this:
<?php
$dir = dirname(__FILE__)."/";
$folder = $dir.'folder/blah/lol/omggz/rofl/';
echo $folder;
?>
replace folder/blah/lol/omggz/rofl/ with a real folder name. If the path matches, then your goodBig Grin
Alright.

That's it?
What about where I link to my PHP in my files. (Index.php for example, when I'm linking to say.. footer.php for example. What do I do with that code?)
Just add $dir after include.

Example:
include $dir.'folder/file.php';
Pages: 1 2 3 4