TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   require problem with absolut paths (http://www.talkphp.com/general/3168-require-problem-absolut-paths.html)

ncorpse 07-24-2008 09:36 AM

require problem with absolut paths
 
Hi everyone

I'm working on a small php application that stores adresses in a mysql database. I'm using a class for printing HTML code.
So I need to include several files in several files:-D
the problem is, that i cannot use absolut paths with require or include.
I tried to define a constant and use it like a document root.
PHP Code:

//define
define('DOCUMENT_ROOT','/var/www/tmp/');
//usage
require(".DOCUMENT_ROOT.".'dir2'); 

Can anyone show me off how I should manage my includes in a project?

Sry for my crappy english

ncorpse

Orc 07-24-2008 09:38 AM

Quote:

Originally Posted by ncorpse (Post 17325)
Hi everyone

I'm working on a small php application that stores adresses in a mysql database. I'm using a class for printing HTML code.
So I need to include several files in several files:-D
the problem is, that i cannot use absolut paths with require or include.
I tried to define a constant and use it like a document root.
PHP Code:

//define
define('DOCUMENT_ROOT','/var/www/tmp/');
//usage
require(".DOCUMENT_ROOT.".'dir2'); 

Can anyone show me off how I should manage my includes in a project?

Sry for my crappy english

ncorpse

try
PHP Code:

require(DOCUMENT_ROOT.'dir2'); 

DOCUMENT_ROOT without the quotes.

Orc 07-24-2008 09:43 AM

By the way, you cant require directories. you should only use require/include for php files.

Now if you want to set an include path, just do this
PHP Code:


set_include_path
('dir2');
require 
'myfile.php'

This will only use require/include to get from the include path dir2, it's limited till you change it back or change it to something else.

delayedinsanity 07-24-2008 10:11 AM

If you need to require a whole directory of files, and I mean *all* the files in that directory, you could do something akin to this:

PHP Code:

    foreach (glob(DOCUMENT_ROOT.'/*.php') as $szFilename)
    {
        require 
$szFilename;
    } 

...assuming that they have the .php extension for that example.
-m

ncorpse 07-24-2008 10:24 AM

Quote:

Originally Posted by Orc (Post 17326)
try
PHP Code:

require(DOCUMENT_ROOT.'dir2'); 

DOCUMENT_ROOT without the quotes.

that works!

No I'm not looking for including a whole directory of files:-)
How can i use this construct inside of this?
PHP Code:

echo "<link rel='stylesheet' type='text/css'  href='./inc/css/stylesheet.css'>\n"

Thank you for your help guys

ncorpse

Evulness 07-24-2008 01:32 PM

Code:


<?php
//define
define('DOCROOT', '/var/www/');
//usage

Echo '<link rel="stylesheet" type="text/css"  href="'.DOCROOT.'inc/css/stylesheet.css">\n"

something like that.... will change your href="" to "/var/www/inc/css/stylesheet.css"



ncorpse 07-25-2008 09:48 AM

Quote:

Originally Posted by Evulness (Post 17332)
Code:


<?php
//define
define('DOCROOT', '/var/www/');
//usage

Echo '<link rel="stylesheet" type="text/css"  href="'.DOCROOT.'inc/css/stylesheet.css">\n"

something like that.... will change your href="" to "/var/www/inc/css/stylesheet.css"



I tried that out it doesn't work.
PHP Code:

define('DOCROOT','/var/www/patric/Adressverwaltung/');
...
echo 
'<link rel="stylesheet" type="text/css"  href="'.DOCROOT.'inc/css/stylesheet.css">'."\n"

It seems that it is not working when i use an absolut path. when i use ./.../ instead it works fine.
Do I need to do something with the php include paths?

Orc 07-25-2008 11:23 AM

Quote:

Originally Posted by ncorpse (Post 17342)
I tried that out it doesn't work.
PHP Code:

define('DOCROOT','/var/www/patric/Adressverwaltung/');
...
echo 
'<link rel="stylesheet" type="text/css"  href="'.DOCROOT.'inc/css/stylesheet.css">'."\n"

It seems that it is not working when i use an absolut path. when i use ./.../ instead it works fine.
Do I need to do something with the php include paths?

I don't think you can use path in href, just do the url base.

ncorpse 07-25-2008 11:30 AM

Quote:

Originally Posted by Orc (Post 17344)
I don't think you can use path in href, just do the url base.

Dammed:-)! You are right mate.
Now it's working


All times are GMT. The time now is 05:25 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0