Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 619221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:37:52+00:00 2026-05-13T18:37:52+00:00

got a strange problem that has so far left me scratching my head. I

  • 0

got a strange problem that has so far left me scratching my head.

I have an index page with a common.php require file a few folders away. In the require file there are six scripts, with all but two of them being in the same folder as common.php.

So for the scripts in the same folder I simply use the file name eg-require(‘filename.php’), which works fine. The two remaining scripts are in an adjacent folder named config so I try using require(‘../config/file.php’) but it doesn’t work.

The strange thing is if I use the relative path from the index file it works?

How comes I can use paths that are relative to common.php if the files are in the same folder but not when in a different folder?

I’m sure there’s a logical explanation that escapes me right now so any help would be greatly appreciated.

thanks
J

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:37:52+00:00Added an answer on May 13, 2026 at 6:37 pm

    As far as I understand, you are including files inside included files. As far as I think, the translation of “../” depends on the current working directory, not the directory in which the included file resides — but I am not sure. Anyway, you can workaround the problem inside the included files with something along these lines:

    Assuming:

    • index.php file resides in C:/inetpub/wwwroot/project1
    • inc01.php file resides in C:/inetpub/wwwroot/project1/include/
    • cfg01.php file resides in C:/inetpub/wwwroot/project1/config/

    index.php contains:

    require( "include/inc01.php" );
    

    To include cfg01.php inside inc01.php regardless of whether the container script is /index.php, /admin/index.php, /products/laptops/index.php:

    require( dirname( dirname( __FILE__ ) ) . "/config/cfg01.php" );
    

    First dirname returns the directory name in which inc01.php exists. Second one returns its parent directory. You can use the constant DIRECTORY_SEPARATOR instead of worrying whether to use forward or back slashes. You can cascade dirname three times to get ../../ and so on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 319k
  • Answers 319k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The problem is that you can't put a call to… May 14, 2026 at 12:12 am
  • Editorial Team
    Editorial Team added an answer Use the SPOOL command: SQL> SPOOL /opt/output SQL> SELECT ...… May 14, 2026 at 12:12 am
  • Editorial Team
    Editorial Team added an answer The whole idea of the VSTS DB is to get… May 14, 2026 at 12:12 am

Related Questions

I am trying to currently embed a media player into certain web content and
I have run into a very strange behaviour I can’t make sense of. I
Bit of a strange problem here... I've got an update query that isn't working,
Ok I got a strange issue that I hope someone could help with I
I've got a class with well over 100 properties (it's a database mapping class)

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.