0

I am trying to create a script and I want to be able to say

require "~/functions/functions1.php";
require "~/functions/functions2.php";
require "~/functions/functions3.php";

but php doesn't seem to understand what the tilde means (and yes this for a linux server). Is there any way I can specify the home dir without actually having to point it to to absolute path? A relative path wouldn't work because I won't know how many folders some of these files will be in

3
Contributors
4
Replies
5
Views
11 Years
Discussion Span
Last Post by paradox814
0

One method would be to define a global var to hold the absolute path to the specified folder. You can then use the global var in the require function to build the path to the file required. Example:

define('FUNCTION_PATH', 'http://127.0.0.1/devsite/functions/');
// the FUNCTION_PATH var can then be used like:
require(FUNCTION_PATH.'functions1.php');
require(FUNCTION_PATH.'functions2.php');
require(FUNCTION_PATH.'functions3.php');
0

There are more than likely server configurations that are preventing you from accessing the file in ~/functions/. This is primarily due to security issues.

Also, you probably should specify which user's home directory you want to go from (i.e. ~johndoe/functions/).

-Fredric

0

There are more than likely server configurations that are preventing you from accessing the file in ~/functions/. This is primarily due to security issues.

Also, you probably should specify which user's home directory you want to go from (i.e. ~johndoe/functions/).

-Fredric

The reason I did it that way was because I can easily go type the following in SSH and it works just fine

ls ~

so it's not which user, the tilde... (at least as I understand it) searches your OWN home dir so there is no need to specify which user at least on the servers I am working on

0

I am trying to create a script and I want to be able to say

require "~/functions/functions1.php";
require "~/functions/functions2.php";
require "~/functions/functions3.php";

but php doesn't seem to understand what the tilde means (and yes this for a linux server). Is there any way I can specify the home dir without actually having to point it to to absolute path? A relative path wouldn't work because I won't know how many folders some of these files will be in

I was really trying to having to avoid doing the absoluate path, even though I know I could call on $_SERVER to generate the path for me in the example you gave. So is there no way to specify your own home dir in PHP?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.