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 6688265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:23:06+00:00 2026-05-26T05:23:06+00:00

There must be something i don’t understand about linking files — but here’s my

  • 0

There must be something i don’t understand about linking files — but here’s my problem.

Basically, i have three files.

  1. generalfunctions.php
  2. wordcount.php
  3. index.php

All three files are in different directories.

B relies on A as follows: ../../../phpfunctions/generalfucntions.php
And when I run B all is well.

But C relies on B as follows: ../wordcount.php

When I run C, I get an error saying that linked file A cannot be found.

The actual error is:

No such file or directory in /…/public_html/plaoul/text/statistics/wordcount.php on line 11

Any ideas what I’m doing wrong??

Thanks for your help.

  • 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-26T05:23:06+00:00Added an answer on May 26, 2026 at 5:23 am

    When you use include to include a file, and you use a relative path as parameter, it will be relative to the current working path.

    What is the current path? It is normally the path of the first called PHP script. The script where the whole execution started. You can get the current working dir with the function getcwd. For example: <?php echo getcwd(); ?> will show you the current working path. You can change the current working path using the chdir function. For example: <?php chdir( '/home/myself' ); ?> – with this command you just changed the current working path!

    So, it is not always good to use relative paths in include, because the current path MAY change.

    But with the usage of the __FILE__ magic constant you can use a sort of relative path as a parameter for an include, making it relative to the file where the include command is. This is good! Because no matter what the current working path is, the include will be always relative to the file which is including!

    So… try the following:

    In B you should include A as follows:

    include( dirname( __FILE__ ) . '/../../../phpfunctions/generalfunctions.php' );
    

    In C you should include B as follows:

    include( dirname( __FILE__ ) . '/../wordcount.php' );
    

    In short: using dirname( __FILE__ ) you can include the file using a path relative to the file where the “include” command is. Otherwise, the path will be relative to the current working path.

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

Sidebar

Related Questions

I think there must be something subtle going on here that I don't know
There must be something obvious I don't realize about C++ with this one. load(string
There's something I don't understand about Scala's collection.mutable.Seq . It describes the interface for
Obviously I can do and DateTime.Now.After - DateTime.Now.Before but there must be something more
I must be missing something stupid here but I can not see it. My
I am sure I am overlooking something very basic here, but I just don't
I know websphere does it, so there must be something that lets apache figure
There must be an easy way to do this, but somehow I can wrap
It feels like there must be some semi-simple solution to this, but I just
I am sure there must be a relatively straightforward way to do this, but

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.