简体   繁体   中英

How do i get the full path of a file

Hello I recently made a private system for creating files on a server when I'm logged in, I also wanted that it checks if an file exist, i do this with the file_exist() function.

The problem is file exist needs the full path like C:\\xampp\\htdocs\\index.php that works but just \\index.php does not works, and most of the times you don't get that path from your webhost.

Is there a way to get the full server path?

Thanks in advance.

Simply use PHP Magic Constant __FILE__ .

$fileName = __FILE__;
var_dump($fileName);

Output

string 'C:\wamp\www\so\x.php' (length=20)

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