4

I've inherited some code:

include('../cfg/db_setup.php');
require('./fpdf/fpdf.php');

I know that ../cfg means start in the current directory, then go up one level and down into the cfg dir. What does the ./fpdf mean? I've never seen a single dot slash used in a file path, and can't seem to find the fpdf directory anywhere on our server, but the code is working so apparently it's there somewhere.

2
  • current directory. btw this is not a good practice for PHP includes. You should use include (dirname(FILE)."../cfg/db_setup.php") to provide absolute paths, not those related to the current directory (that might change by many means) Commented Mar 15, 2011 at 21:30
  • I'm aware of that, thanks. Like I said, this is code I inherited. I need to find all the referenced files before I can start dealing with absolute paths. Commented Mar 15, 2011 at 21:46

4 Answers 4

22

Just a note.

Relative paths don't are relative to the current include_path.

Relative paths, such as . or ../ are relative to the current working directory. The working directory is different if you run a script on CGI or command line or if a script is included by another script in another directory.

Therefore theoretically is not possible to be sure where these paths are pointing to without to know the context :P

To be sure, if PHP < 5.3:

include(dirname(__FILE__) . '/../cfg/db_setup.php');
require(dirname(__FILE__) . '/fpdf/fpdf.php');

If PHP >= 5.3:

include(__DIR__ . '/../cfg/db_setup.php');
require(__DIR__ . '/fpdf/fpdf.php');
Sign up to request clarification or add additional context in comments.

Comments

4

. is defined as the current folder.

So, if the PHP script is located at /path/to/script/, then the second statement will look for /path/to/script/fpdf/fpdf.php

1 Comment

Thank you. I'm not used to dealing with relative paths.
2

./ is the current directory. ./fpdf/ should be on the same path as the including file, or somewhere on the off the php include_path.

Comments

0

./ - this means in the current path

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.