__FILE__ 是什么意思?
我有来自 Codeigniter index.php
的以下代码,
我的理解是,
如果 /
位于 $system_folder
中的字符串位置(在本例中为 CIcore_1_7_1)是假
, 如果 realpath
函数存在且 (?) 不 false
, $system_folder
被分配给 (?) /$system_folder
。 否则,将 $system_folder
分配给 $system_folder
,并将 \\
替换为 /
。
Q1. realpath函数是什么意思?
Q2。这意味着什么?
@realpath(dirname(__FILE__))
Q3。我说得对吗?难道我有什么误会吗?
Q4。您需要以下哪种情况?
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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
realpath()
函数为您提供文件系统路径,其中任何符号链接和目录遍历(例如../../)都已解决。dirname()
函数只提供目录,而不提供其中的文件。__FILE__
是一个神奇的常量,它为您提供当前 .php 文件的文件系统路径(__FILE__
所在的文件系统路径,而不是包含它的文件系统路径。听起来不错。
这是从 Windows 风格 (\) 路径转换为 Unix 风格 (/)。
The
realpath()
function gives you the file-system path, with any symbolic links and directory traversing (e.g. ../../) resolved. Thedirname()
function gives you just the directory, not the file within it.__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.Sounds about right.
This is to translate from Windows style (\) paths to Unix style (/).
__FILE__
只是当前文件的名称。realpath(dirname(__FILE__))
获取文件所在目录的名称——本质上是应用程序安装的目录。而@
是 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.您需要使其在不同操作系统之间的路径分隔符保持一致。 Windows 使用 \ 而 *nix 使用 /,您可以保留 /。
You need this to be consisten in path separators between different operating systems. Windows uses \ and *nix uses /, you keep with /.
此回声可能有助于澄清差异:
This echo might help clarify the difference: