Avatar of Glen Gibb
Glen Gibb
Flag for Canada asked on

PHP -- create and use a code library

Experts,

I'm trying to create a set of reusable objects to use in my websites.  No problem as far as the coding, but I'm confused by absolute and relative path names.

I get the $SERVER['DOCUMENT_ROOT'] business, and I can move up a level with ../ .  

This code: " $action = $_SERVER['DOCUMENT_ROOT'] . "/tools/add_image.php";" produces a 404 error.  (But the file does actually exist at the path specified.)

Modifying it thusly: "$action = "/tools/add_image.php"; works from one directory, but not from another further down the tree.  That needs $action = "../tools/add_image.php";

I need to call a POST from somewhere down the tree and have it directed to a page at the document root.

How do I consistently access a file at the document root, or even better, a library folder even further up the tree?

Capt
Web ServersPHP

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Dave Baldwin

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Ray Paseur

You can also use this script, shown here in its entirety ;-)
<?php phpinfo();

Open in new window

Glen Gibb

ASKER
Thanks for your replies, Experts.

I still need some clarification.

1.  I know about phpinfo().  At least I've been using it to find out what modules are installed on my server, etc.  And as I said, $_SERVER['documentroot'] points me to the exact file that I need.  So drive mapping maybe isn't the issue.

2.  I need to $_POST to add_image.php which lies in the /tools/ folder of my website.  So how to access that file consistently?  Do I just give it http://www.simpletek.biz/tools/add_image.php in the form's action="" ?

I hope there are no "dumb" questions!

Capt
Ray Paseur

No dumb questions at all, but programming is a process that requires highly detailed and precise expressions.  In PHP all variables are case-sensitive.

 $_SERVER['documentroot']

is almost certainly an undefined variable.  Instead, you probably want  

$_SERVER['DOCUMENT_ROOT']

... and it would be helpful if you can show us the value in that variable, as well as the URL of your action script.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Dave Baldwin

$_SERVER['DOCUMENT_ROOT'] on both IIS and Apache gives an absolute path on the server.  However, if you are on a Linux server that has you 'sandboxed' with 'chroot', that will not do you any good because all you will be allowed is paths relative to your account or maybe just your web root.  I know that Godaddy does that to keep each user isolated from the others and I'm sure other hosts do too.
Glen Gibb

ASKER
Thank you, Experts.

Your advice was all on the money.

The culprit turned out to be the jquery.form.js that I am using to verify my inputs before submission.   It was giving an error -- .httpData is not a function.

Not sure why this is preventing the POST, but by suppressing the jQuery, the basic functionality works as planned.

Many thanks for your timely and insightful suggestions.
Ray Paseur

Thanks for the points and thanks for using EE, ~Ray
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.