Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute path without symlink resolution / Keep user in home directory

Is there a way in PHP how to determine an absolute path given a relative path without actually resolving symlinks? Something like the realpath function but without symlink resolution.

Or alternatively, is there some easy way to check whether user (who uses my browsing PHP script to view files) did not accidentally step out of Apache virtual host's home directory? (or disallow him to use the nasty . and .. in paths)

Thanks!

like image 487
NumberFour Avatar asked Jun 29 '11 10:06

NumberFour


People also ask

What does c mean in a file path?

If the path starts with a single component separator, the drive from the current directory is applied. For example, if the file path is \utilities and the current directory is C:\temp\ , normalization produces C:\utilities .

What is absolute path and relative path in Windows?

In simple words, an absolute path refers to the same location in a file system relative to the root directory, whereas a relative path points to a specific location in a file system relative to the current directory you are working on.

Are Symlinks relative or absolute?

Symbolic links can either be absolute or relative links. Absolute links are links that specify each portion of the path name; relative links are determined relative to where relative–link specifiers are in a specified path.


1 Answers

I don't know PHP native solution for this, but one nice absolute path implementation is here: http://www.php.net/manual/en/function.realpath.php#84012

like image 164
Karolis Avatar answered Nov 15 '22 13:11

Karolis