Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

wrong directory... 1

Status
Not open for further replies.

Programmer76

Programmer
Jul 25, 2006
35
CA
Hi,

Can someone tell me how to best handle requiring files with the require_once function.

I have a files structure like this:

Code:
WebsiteRoot
  admin
    - myadminpage.php
  includes
    inc
      - admin.inc
  - index.php

That is the basic directoyr structure. myadminpage.php includes the admin.inc file...I see that this is a common problem adn was hoping on advice of how to best handle this?

Anyone have some suggestions?

CES
 
The error is:

print_header(includes/inc/admin.inc): failed to open stream: No such file or directory in...
 
not sure why this is a common problem. this is just an issue of unix file and directory conventions.

if the websiteroot is GENUINELY the root directory then something like this would work:
Code:
include "/includes/inc/admin.inc";
from anywhere in your site as you are providing an absolute path from the root.

a relative path from myadminpage.php would look like
Code:
include "../includes/inc/admin.inc";

so
starting with a forward slash designates that you start from root.
starting with a "./" means you are creating a relative path from the current working directory
starting with nothing means the same as above BUT it include/require may pick up the wrong file if you have an identically named path in your "include_path" directive
starting (or using anywhere in the path) with "../" means "go up one level. so
Code:
/directory1/file.php
is the same as
Code:
/directory1/directory2/../file.php
 
Thanks for the explanation jpadie, gotta get a star for that solid explanation.

However, I don't think I mentioned enough details.

I do understand the different was to move around directories but here is my problem.
Currently the files are not actually in the root. They are actually in webroot/dev/. So I could make the reference /dev/includes/ everywhere but then I would have to get rid of the /dev/ in every page once the files are moved to the webroot.

Any ideas...I am sure I am just being brain dead here lol...

Thanks,

CES
 
yes.

use the path
Code:
include DEV."/directory1/directory2" ...etc

include this in your dev code
Code:
define("DEV", "/dev");
and in your production code
Code:
define("DEV", "");

alternatively you could add the webroot/dev directory to your include path in your development code and remove it in your production code. this can be done in the scripts (i.e. you don't have to amend php.ini).
 
Thanks that is what I was thinking...thanks for the suggestions!

CES
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top