What does __FILE__ mean?

后端 未结 3 761
醉话见心
醉话见心 2020-12-24 06:32

I have the following code from Codeigniter index.php

My understanding is that,

If / of string position in $system_folder

相关标签:
3条回答
  • 2020-12-24 07:06

    __FILE__ is simply the name of the current file. realpath(dirname(__FILE__)) gets the name of the directory that the file is in -- in essence, the directory that the app is installed in. And @ is PHP's extremely silly way of suppressing errors.

    0 讨论(0)
  • 2020-12-24 07:22
    __FILE__
    

    The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, FILE always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances.


    string dirname  ( string $path  )
    

    Given a string containing a path to a file, this function will return the name of the directory.


    str_replace("\\", "/", $system_folder)
    

    You need this to be consisten in path separators between different operating systems. Windows uses \ and *nix uses /, you keep with /.

    0 讨论(0)
  • 2020-12-24 07:25
    1. The realpath() function gives you the file-system path, with any symbolic links and directory traversing (e.g. ../../) resolved. The dirname() function gives you just the directory, not the file within it.

    2. __FILE__ is a magic constant that gives you the filesystem path to the current .php file (the one that __FILE__ is in, not the one it's included by if it's an include.

    3. Sounds about right.

    4. This is to translate from Windows style (\) paths to Unix style (/).

    0 讨论(0)
提交回复
热议问题