using <?php include.....?>
I am trying to set up a web site in PHP (which is somewhat new to me). On my local machine, it all works just fine. But on the server things don't work OK and I'm not sure why.
My document root is public_html
off of that, I have includes, jpgs and a few other folders. SO, it's
I would like to be able to reference files in the includes folder without a direct path from where it is being referenced.
SO, something like <?php include('includes/xxx.php'); ?>
current I include the absolute path from the document root and that seems to work but it feels clunky. HOWEVER, on the server, this also does not work. On the server, where the documen root is public_html, I have to go ../../incudes/xxx.php, but if the file containing the reference is nested further I would have to have ../../../ etc.
BUT I still cannot access files in the include folder from any place other than public_html folder.
$paths = '.';
$paths = 'public_html/includes/';
$paths = '/jpgs';
$paths = get_include_path();
You can use $_SERVER['DOCUMENT_ROOT'] to create a consistent starting point for any file path, e.g.:
I get a permission denied when I do that.
Here's an example of the problem: I am using a header.php file. In that file I have a reference to an image, the jpgs folder (public_html/jpgs). If I reference that from a top level file, it's OK. BUT if the file is in another nested folder, like, say, in public_html/gallery/newyork then the 'src=jpgs/image.jpg' won't work (of course). I would like to have an absolute path from public_html so I don't have to worry about where these files are being accessed.
Now my top level path is:
and from the top level (i.e., public_html) I can access the jpg folder which is public_html/jpgs BUT if I'm in a lower folder like:
public_html/gallery/newyork the the path /home/xerxes11/public_html/jpgs can't be found. This is what I find confusing.
It would help to see the exact code that causes this error along with a copy of the complete error message.
Originally Posted by RonNYC
As far as replies #4 and #5 go, HTML SRC attributes are different than PHP file system paths (such as include() would use). For SRC (or HREF) attributes, you can simply indicate it's relative to the document root with a leading slash:
echo "<img src='/jpgs/image.jpg' alt='' />";
I fixed some things
But it seems cludgey to me.
The paths (hrefs and src) to the various files are now //myserver.com/~xerxes11/jpgs/
and that works.
And for the includes:
but the /home/xerxes11 part bothers me. I just feel it should be either /includes if public_html is the document root or public_html/includes/ OH WELL, it does work. SORRY TO BE A BOTHER!
NogDog is absolutely right.
Originally Posted by RonNYC
is the consistent way to ensure correct paths.
If you have permissions problems, you need to first sort out the chmod on those
directories to which you are being denied access.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread