Page 1 of 1

Referencing an unrelated folder with "../"?

Posted: Wed Sep 23, 2009 7:23 pm
by OrcaSoul
I'm new to php, so please excuse if it's a bit basic.

I have set up a folder under my localhost with the following files/folders:

Folder: OrcaTools
File: index.php (primary php)
File: about.php (the about page php)

Folder: OrcaTools/includes
File: orcatools.inc (defines, other vars + global functions)
File: template.inc (functions specific to several pages)

Folder: OrcaTools/templates
File: orcatools.tpl (template for home page - all other templates fit in a content div in this)
File: about.tpl (template for about page content)
File: orcatools.css (css file for orcatools.tpl - and for all other templates in the content div)

orcatools.tpl has a line that links to orcatools.css:

Code: Select all

<link rel="stylesheet" href="templates/orcatools.css" type="text/css" media='screen' />

index.php creates a new orcatoolsTemplate, sets some vars & calls the showOrcaTools function in template.inc, which then calls orcatools.tpl to display the home page.

The home page has an About button, which calls about.php, which reads it's template about.tpl.

And this works exactly as I want it to.

The problem occurs when I try to put about.php in it's own subfolder OrcaTools/About.

I change the following in the relocated login.php:

Code: Select all

require_once "includes/orcatools.inc";
require_once "includes/template.inc";
require_once "includes/validate.inc";
 
becomes

Code: Select all

require_once "../includes/validate.inc";
require_once "../includes/orcatools.inc";
require_once "../includes/template.inc";
 
in order to find the template files - which it does not seem to be able to do.

When the about page appears, I see the text from the about.php, but in a linear form, not the styled display.

I've used the "../" to indicate that the reference is from the root rather then directly to the current folder.

So what's happening here - what am I doing wrong?

Re: Referencing an unrelated folder with "../"?

Posted: Wed Sep 23, 2009 11:16 pm
by Robert07
You should be able to reference the files from anywhere like this:

Code: Select all

 
<link rel="stylesheet" href="/OrcaTools/templates/orcatools.css" type="text/css" media='screen' />
 
and this:

Code: Select all

 
require_once "/OrcaTools/includes/orcatools.inc";
require_once "/OrcaTools/includes/template.inc";
require_once "/OrcaTools/includes/validate.inc";
 

Re: Referencing an unrelated folder with "../"?

Posted: Wed Sep 23, 2009 11:35 pm
by OrcaSoul
I thought so as well - but I made the changes and got the following error:

Code: Select all

Warning: require_once(OrcaTools/includes/orcatools.inc) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\OrcaTools\about\about.php on line 7
Line 7 is

Code: Select all

require_once "OrcaTools/includes/orcatools.inc";

Re: Referencing an unrelated folder with "../"?

Posted: Wed Sep 23, 2009 11:51 pm
by Robert07
There is a big difference between:

Code: Select all

 
require_once "OrcaTools/includes/orcatools.inc";
 
and:

Code: Select all

 
require_once "/OrcaTools/includes/orcatools.inc";
 
The latter is what I recommended. One is an absolute path which starts from the web root, the other (the one you tried) is a relative path.

Re: Referencing an unrelated folder with "../"?

Posted: Thu Sep 24, 2009 12:07 am
by OrcaSoul
OK, with the slash is what I had - I tried it the other way before responding, forgot to change it back. Line 7 is:

Code: Select all

require_once "/OrcaTools/includes/orcatools.inc";
 
Sorry for the confusion... :oops:

Edit to add: I also tried it with the full actual path on my disk, it still did not find it...

Edit again: Scratch that last - I had a backwards slash in there...the full path did work.

Which will be fine for now while I am developing this - but I do need to find out the way to do it so that it runs when I upload it to the real server...

Thanks for the help.

Re: Referencing an unrelated folder with "../"?

Posted: Thu Sep 24, 2009 11:21 am
by Robert07
As long as you keep that OrcaTools folder directly in your webroot and the file structure is the same, it should work on any server.