PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > setting the document root path in linux
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
setting the document root path in linux

Réponse
 
LinkBack Outils de la discussion
Vieux 19/09/2007, 08h11   #1 (permalink)
tbt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut setting the document root path in linux


Hi

I'm a newbie to php and I'm using

require_once($_SERVER['DOCUMENT_ROOT']."/includes/class.announcement.php");

to import pages in php. This works fine on a windows environment. However
when I move this application to a linux environment the files dont get
imported properly. This is because in a windows environment
$_SERVER['DOCUMENT_ROOT'] returns c:/xampp/htdocs etc.
but in a linux environment returns /home/servers etc.

How can this be rectified so that the path is properly picked up in a linux
environment
--
View this message in context: http://www.nabble.com/setting-the-do...html#a12771923
Sent from the PHP - General mailing list archive at Nabble.com.
  Réponse avec citation
Vieux 19/09/2007, 08h24   #2 (permalink)
Chris
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] setting the document root path in linux

tbt wrote:
> Hi
>
> I'm a newbie to php and I'm using
>
> require_once($_SERVER['DOCUMENT_ROOT']."/includes/class.announcement.php");
>
> to import pages in php. This works fine on a windows environment. However
> when I move this application to a linux environment the files dont get
> imported properly. This is because in a windows environment
> $_SERVER['DOCUMENT_ROOT'] returns c:/xampp/htdocs etc.
> but in a linux environment returns /home/servers etc.
>
> How can this be rectified so that the path is properly picked up in a linux
> environment


Don't rely on document root.

I'm surprised it worked on windows, you were lucky - 90% of the time
it's not there or not correct anyway.

If it's in the same directory as the current file, do:

require(dirname(__FILE__) . '/includes/class.announcement.php');

__FILE__ is a built in constant that tells you the full path to the
current file.

dirname() takes the filename out of that and gives you just the current
directory (see http://www.php.net/dirname ).

Then add the rest of the on the end.

--
Postgresql & php tutorials
http://www.designmagick.com/
  Réponse avec citation
Vieux 19/09/2007, 08h28   #3 (permalink)
Lammi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: setting the document root path in linux

On 19 Sep., 09:11, nadeesh...@yahoo.com (tbt) wrote:

> when I move this application to a linux environment the files dont get
> imported properly. This is because in a windows environment
> $_SERVER['DOCUMENT_ROOT'] returns c:/xampp/htdocs etc.
> but in a linux environment returns /home/servers etc.


what's wrong with /home/servers/bla/blubb/omething?



  Réponse avec citation
Vieux 19/09/2007, 15h46   #4 (permalink)
Jim Lucas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] setting the document root path in linux

tbt wrote:
> Hi
>
> I'm a newbie to php and I'm using
>
> require_once($_SERVER['DOCUMENT_ROOT']."/includes/class.announcement.php");
>
> to import pages in php. This works fine on a windows environment. However
> when I move this application to a linux environment the files dont get
> imported properly. This is because in a windows environment
> $_SERVER['DOCUMENT_ROOT'] returns c:/xampp/htdocs etc.
> but in a linux environment returns /home/servers etc.
>
> How can this be rectified so that the path is properly picked up in a linux
> environment

are you running apache on windows and linux?

if so, setup a .htaccess file that has a line in it that modifies the php include path

place that .htaccess at your web root and you won't have to play with paths, you would call
require_once 'includes/class.announcement.php'; instead

Fix your include paths and you wont have to worry if the system will have what it should in the
$_SERVER['DOCUMENT_ROOT'].

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h26.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08868 seconds with 12 queries