Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does __FILE__ mean?

I have the following code from Codeigniter index.php

My understanding is that,

If / of string position in $system_folder (in this case CIcore_1_7_1) is false, and if realpath function exists AND (?) is not false, $system_folder is assigned to (?) /$system_folder. else $system_folder is assigned to $system_folder with replacing \\ with /.

Q1. What does realpath function means?

Q2. What does this mean?

@realpath(dirname(__FILE__)) 

Q3. Am I right? Do I have any misunderstanding?

Q4. What kind of situation do you need the following?

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

$system_folder = "CIcore_1_7_1";  /* |--------------------------------------------------------------- | SET THE SERVER PATH |--------------------------------------------------------------- | | Let's attempt to determine the full-server path to the "system" | folder in order to reduce the possibility of path problems. | Note: We only attempt this if the user hasn't specified a  | full server path. | */  if (strpos($system_folder, '/') === FALSE) {     if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)     {         $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;     } } else {     // Swap directory separators to Unix style for consistency     $system_folder = str_replace("\\", "/", $system_folder);  } 
like image 332
shin Avatar asked Oct 01 '09 20:10

shin


People also ask

What does __ FILE __ mean in Python?

When a module is loaded from a file in Python, __file__ is set to its path. You can then use that with other functions to find the directory that the file is located in.

What does __ FILE __ mean in PHP?

__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.

What does OS path dirname (__ file __) do?

path. dirname() method in Python is used to get the directory name from the specified path.

What is __ PATH __ in Python?

If you change __path__ , you can force the interpreter to look in a different directory for modules belonging to that package. This would allow you to, e.g., load different versions of the same module based on runtime conditions.


1 Answers

  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 (/).

like image 148
Greg Avatar answered Oct 05 '22 00:10

Greg