我有来自 Codeigniter index.php
我的理解是,
如果 $system_folder
(在本例中为 CIcore_1_7_1)中字符串位置的 /
为 false
,
如果 realpath
函数存在且 (?) 不是 false
,
$system_folder
分配给 (?) /$system_folder
。
否则将 $system_folder
分配给 $system_folder
,并将 \\
替换为 /
。
第一季度。 realpath函数是什么意思?
第二季度。这是什么意思?
@realpath(dirname(__FILE__))
第三季度。我对吗?我有什么误会吗?
第四季度。你需要以下什么样的情况?
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);
}
最佳答案
realpath()
函数为您提供文件系统路径,并解析任何符号链接(symbolic link)和目录遍历(例如 ../../)。dirname()
函数只为您提供目录,而不是其中的文件。__FILE__
是一个神奇的常量,它为您提供当前 .php 文件的文件系统路径(__FILE__
所在的文件系统路径,而不是它包含的文件,如果它是 include。听起来不错。
这是将 Windows 风格 (\) 路径转换为 Unix 风格 (/)。
关于php - __FILE__ 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1506459/