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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:42:06+00:00 2026-05-17T20:42:06+00:00

I have the following files structure: temp main index.php a.php b.php Here are the

  • 0

I have the following files structure:

temp
    main
        index.php
    a.php
    b.php

Here are the files;

index.php

echo "index.php ---> " . __DIR__ . "<br />";

require('../a.php');

echo "OK<br />"

a.php

echo "a.php ---> " . __DIR__ . "<br />";

require('./b.php');

echo "a is here<br />"

b.php

echo "b is here<br />"

When index.php is called I got the following error:

index.php ---> D:\Programs\WampServer 2\www\temp\main
a.php ---> D:\Programs\WampServer 2\www\temp

Warning: require(./b.php) [function.require]: failed to open stream: No such file or directory in D:\Programs\WampServer 2\www\temp\a.php on line 5

Fatal error: require() [function.require]: Failed opening required './b.php' (include_path='.;C:\php5\pear') in D:\Programs\WampServer 2\www\temp\a.php on line 5

I have noticed that if I change

require('./b.php');

to

require('b.php');

Why is that ?
it works as expected.

  • 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-17T20:42:07+00:00Added an answer on May 17, 2026 at 8:42 pm

    When you use include or require, the file that you include will act as if it is part of the script that included it. In this case, the file a.php might live in the same directory as b.php, but when the code is running, it is running in the context of index.php. If you had used __FILE__ rather than __DIR__, you would see that a.php returns the same value as index.php when it is running as an included file on index.php.

    Since the relative path changes depending on where files are used, it’s always best to use an absolute path relative to the server root. If the machine is configured normally, that will start with $_SERVER["DOCUMENT_ROOT"], then add the application path and the includes path. On some shared hosting servers, you might have to hard-code the root somewhere (or add it to the .htaccess file).

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

Sidebar

Related Questions

Hello I have the following files structure: /public_html(docroot) - /public /css /js index.php -
I have the following folder structure with files: index.php includes/header.php includes/conn.php contents/ad_list.php contents/ad_posting.php in
I have the following file structure (XML files 'index.xml' in nested folders): index.xml foo/index.xml
I have the following directory structure in htdocs: htdocs/ .htaccess index.php foo/ bar/ priv/
I have the following structure: Root directory index.php [ mobile ] index.php [images] What
I have the following files structure: On server 'site1.com': - images\background.jpg - index.html On
I have the following Project Structure / src/ # src-files for the app org.mayapp.main.Main/
I have a Python project with following directory structure: /(some files) /model/(python files) /tools/(more
I have two Excel files contains the following structure, EmployeeAllDtl.xlsx id email name age
I have the following file structure: |- index.html vendor |- jquery.min.js (some libraries) js

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.