file_exists在XAMPP上返回false

I have XAMPP installed on a widows 7 machine and if I execute: file_exists("ss.txt") I get true (ss.txt is in my docroot e:\www\)

If I move ss.txt to e:\www\var and call file_exists("/var/ss.txt") I get false but file_exists("var/ss.txt") returns true - Why?

I cannot change where to look ("/var/ss.txt") because that is an entry from the DB and there is a production server running Ubuntu that uses the same data.

You've said you can't change the path in your script because it pulls from a database. Just set up the directory structure on your development machine the same way it will be set up on your server. (i.e. Don't create the directory 'e:\www\var', create the directory 'e:\var'.)

As far as the why, as other people have said, '/var/ss.txt' is an absolute path, and 'var/ss.txt' is a relative path.

/var/ss.txt corresponds to a path starting at the root of your drive, while var/ss.txt is a path starting from where the script is executed (e:\www\ in your case).

You can tweak the path you get from the db by preceeding it by a dot . to indicate the path starts where the script is executed.

$path = '/var/ss.txt';
$relativePath = '.' . $path; // equivalent to "./var/ss.txt"
file_exists($relativePath);

You can also trim any / from the start of your path:

$path = '/var/ss.txt';
$relativePath = ltrim($path, '/'); // equivalent to "var/ss.txt"
file_exists($relativePath);

ltrim documentation