What is the right way for PHP to include a Mac?

Running Mac OS X 10.5.8 with pre-installed PHP 5.2.11. Using Coda 1.6.10.

I write PHP files and then view them from a file, not from a server. This worked fine until I tried PHP. They do not work as a relative path, only as absolute from the root of the disk.

Is it possible to use expressions such as

include_once "common / header.php";

without specifying my entire file path as follows:

include_once "/ Volumes / Macintosh HD / Users / neil / Desktop / Website / ColoredLists_v1.0 / common / base.php";

where ColoredLists_v1.0 is the directory with all the website files. I tried solutions like adding _SERVER [DOCUMENT_ROOT] or dirname ( File ) in the file path, but this did not work as the variables were not set. Is there any simple way to do this or a configuration that I can change to look in a specific default directory instead of looking at the root of the disk? Currently displaying echo_include_path .:

When I include this line at the beginning of the script, it works:

set_include_path ('/ Volumes / Macintosh HD / Users / neil / Desktop / Website / ColoredLists_v1.0');

However, if I want to do this for all my scripts, I cannot make the change permanent. Even after I edited the Unix include_path in my php.ini, it does not work.

UPDATE: , sureshot - Apache . Mac, . httpd.conf, localhost, . , 80, , , . Coda "", url, . - , , .

+3
4

.

require_once(dirname(__FILE__) . '/example.php');
+2

Try

set_include_path(
    '/Volumes/Macintosh HD/Users/neil/Desktop/Website/ColoredLists_v1.0' .
    PATH_SEPARATOR . 
    get_include_path());

include

php.ini include_path ( MAMP, php.ini)

0

This is really an include_path problem. The default value is .:/usr/lib/php; maybe if you ran the PHP command from the directory where your scripts are located, would it be nice?

0
source

this works every time for me:

<?php require_once($_SERVER['DOCUMENT_ROOT'] . '/common/header.php'); ?>

0
source

Source: https://habr.com/ru/post/1736817/


All Articles