FILE__ __ ne demek?

3 Cevap

Ben Kodigniter index.php aşağıdaki kodu var

Benim anlayış olduğunu,

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

Q1. Ne realpath fonksiyon ne demek?

Q2. Bu ne anlama geliyor?

@realpath(dirname(__FILE__))

Q3. Haklı mıyım? Ben herhangi bir yanlış anlama var mı?

Q4. Durumun ne tür aşağıdaki gerekiyor?

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

+ + + + + + + + + + + + + + + + + + + + + +

Kod

$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); 
}

3 Cevap

  1. realpath() function gives you the file-system path, with any symbolic links and directory traversing (e.g. ../../) resolved. The dirname() işlev, sadece dizini değil, içindeki dosyayı verir.

  2. __FILE__ is a magic constant that gives you the filesystem path to the current .php file (the one that __FILE__, o bir dahil olursa tarafından dahil olan olmayan biridir.

  3. Doğru geliyor.

  4. Bu, Windows tarzı (\) yolları Unix-stili (/) çevirmek için.

__FILE__ sadece geçerli dosyanın adıdır. Özünde, app içeri yüklü Ve @ hatalarını bastırmak PHP'nin son derece aptalca yoludur dizinde - realpath(dirname(__FILE__)) dosyası olan dizinin adını alır.

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

Farklı işletim sistemleri arasında yol ayırıcılar consisten olması için bu gerekiyor. Windows \ kullanır ve * nix / kullanır / ile tutmak.