简体   繁体   中英

File path in php require

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.

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');

. 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

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

./ - 这意味着在当前的路径中

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM