Comment définir un chemin absolu inclus dans PHP

Mots clés : phpphp

meilleur 5 Réponses Comment définir un chemin absolu inclus dans PHP

vote vote

93

define( 'ROOT_DIR', dirname(__FILE__) ); 
require_once( ROOT_DIR.'/include/functions.php' ); 
vote vote

86

$root = $_SERVER['DOCUMENT_ROOT']; include($root."/path/to/file.php"); 
vote vote

70

ini_set("include_path", "/your_include_path:".ini_get("include_path")); 
vote vote

60

include('/includes/header.php');  
 /home/username/public_html <- absolute path   public_html <- relative path   ./public_html <- same as the path above   ../username/public_html <- another relative path   
require_once(__DIR__ . '/Factories/ViewFactory.php'); 
vote vote

56

C:\wamp\www\ 
<?php if(!defined('MY_ABS_PATH')) define('MY_ABS_PATH',$_SERVER['DOCUMENT_ROOT'].'MyProyect/') 

Questions similaires