1. <legend id='ZlPf1'><style id='ZlPf1'><dir id='ZlPf1'><q id='ZlPf1'></q></dir></style></legend>
  2. <small id='ZlPf1'></small><noframes id='ZlPf1'>

      <bdo id='ZlPf1'></bdo><ul id='ZlPf1'></ul>
  3. <tfoot id='ZlPf1'></tfoot>
    <i id='ZlPf1'><tr id='ZlPf1'><dt id='ZlPf1'><q id='ZlPf1'><span id='ZlPf1'><b id='ZlPf1'><form id='ZlPf1'><ins id='ZlPf1'></ins><ul id='ZlPf1'></ul><sub id='ZlPf1'></sub></form><legend id='ZlPf1'></legend><bdo id='ZlPf1'><pre id='ZlPf1'><center id='ZlPf1'></center></pre></bdo></b><th id='ZlPf1'></th></span></q></dt></tr></i><div id='ZlPf1'><tfoot id='ZlPf1'></tfoot><dl id='ZlPf1'><fieldset id='ZlPf1'></fieldset></dl></div>

    1. getcwd() 和 dirname(__FILE__) 之间的区别?我应该使用哪个?

      Difference Between getcwd() and dirname(__FILE__) ? Which should I use?(getcwd() 和 dirname(__FILE__) 之间的区别?我应该使用哪个?)
    2. <legend id='YmeYv'><style id='YmeYv'><dir id='YmeYv'><q id='YmeYv'></q></dir></style></legend>
    3. <small id='YmeYv'></small><noframes id='YmeYv'>

          <bdo id='YmeYv'></bdo><ul id='YmeYv'></ul>

        • <tfoot id='YmeYv'></tfoot>

              • <i id='YmeYv'><tr id='YmeYv'><dt id='YmeYv'><q id='YmeYv'><span id='YmeYv'><b id='YmeYv'><form id='YmeYv'><ins id='YmeYv'></ins><ul id='YmeYv'></ul><sub id='YmeYv'></sub></form><legend id='YmeYv'></legend><bdo id='YmeYv'><pre id='YmeYv'><center id='YmeYv'></center></pre></bdo></b><th id='YmeYv'></th></span></q></dt></tr></i><div id='YmeYv'><tfoot id='YmeYv'></tfoot><dl id='YmeYv'><fieldset id='YmeYv'></fieldset></dl></div>
                  <tbody id='YmeYv'></tbody>

                本文介绍了getcwd() 和 dirname(__FILE__) 之间的区别?我应该使用哪个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                PHP 中的区别是什么

                getcwd()目录名(__文件__)

                当我从 CLI 回显时,它们都返回相同的结果

                echo getcwd()."
                ";echo 目录名(__FILE__)."
                ";

                返回:

                /home/user/Desktop/testing//家/用户/桌面/测试/

                哪个最好用?有关系吗?更高级的 PHP 开发人员更喜欢什么?

                解决方案

                __FILE__ 是一个 魔法常量 包含您正在执行的文件的完整路径.如果你在一个包含中,它的路径将是 __FILE__ 的内容.

                所以有了这个设置:

                /folder/random/foo.php

                /folder/random/bar/bar.php

                你得到这个输出:

                /folder/random/文件夹/随机-------/文件夹/随机/文件夹/随机/条

                所以 getcwd() 返回你开始执行的目录,而 dirname(__FILE__) 是文件相关的.

                在我的网络服务器上,getcwd() 返回最初开始执行的文件的位置.使用 CLI,它与执行 pwd 时得到的结果相同.这由 CLI SAPI 文档 和评论支持在 getcwd 手册页上:

                <块引用>

                CLI SAPI 确实 - 与其他 SAPI 不同 - 不会自动将当前工作目录更改为启动脚本所在的目录.

                所以喜欢:

                thom@griffin/home/thom $ echo "<?php echo getcwd() . '
                ' ?>">>测试.phpthom@griffin/home/thom $ php test.php/家/汤姆thom@griffin/home/thom $ cd ..汤姆@格里芬/home $ php 汤姆/test.php/家

                当然,也请参见http://php.net/manual/en/function.getcwd.php

                UPDATE:自 PHP 5.3.0 起,您还可以使用魔术常量 __DIR__,它等效于 dirname(__FILE__).>

                In PHP what is the difference between

                getcwd()
                dirname(__FILE__)
                

                They both return the same result when I echo from CLI

                echo getcwd()."
                ";
                echo dirname(__FILE__)."
                ";
                

                Returns:

                /home/user/Desktop/testing/
                /home/user/Desktop/testing/
                

                Which is the best one to use? Does it matter? What to the more advanced PHP developers prefer?

                解决方案

                __FILE__ is a magic constant containing the full path to the file you are executing. If you are inside an include, its path will be the contents of __FILE__.

                So with this setup:

                /folder/random/foo.php

                <?php
                echo getcwd() . "
                ";
                echo dirname(__FILE__) . "
                " ;
                echo "-------
                ";
                include 'bar/bar.php';
                

                /folder/random/bar/bar.php

                <?php
                echo getcwd() . "
                ";
                echo dirname(__FILE__) . "
                ";
                

                You get this output:

                /folder/random
                /folder/random
                -------
                /folder/random
                /folder/random/bar
                

                So getcwd() returns the directory where you started executing, while dirname(__FILE__) is file-dependent.

                On my webserver, getcwd() returns the location of the file that originally started executing. Using the CLI it is equal to what you would get if you executed pwd. This is supported by the documentation of the CLI SAPI and a comment on the getcwd manual page:

                the CLI SAPI does - contrary to other SAPIs - NOT automatically change the current working directory to the one the started script resides in.

                So like:

                thom@griffin /home/thom $ echo "<?php echo getcwd() . '
                ' ?>" >> test.php
                thom@griffin /home/thom $ php test.php 
                /home/thom
                thom@griffin /home/thom $ cd ..
                thom@griffin /home $ php thom/test.php 
                /home
                

                Of course, see also the manual at http://php.net/manual/en/function.getcwd.php

                UPDATE: Since PHP 5.3.0 you can also use the magic constant __DIR__ which is equivalent to dirname(__FILE__).

                这篇关于getcwd() 和 dirname(__FILE__) 之间的区别?我应该使用哪个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <tbody id='RACUV'></tbody>
                  <bdo id='RACUV'></bdo><ul id='RACUV'></ul>

                  <tfoot id='RACUV'></tfoot>
                • <i id='RACUV'><tr id='RACUV'><dt id='RACUV'><q id='RACUV'><span id='RACUV'><b id='RACUV'><form id='RACUV'><ins id='RACUV'></ins><ul id='RACUV'></ul><sub id='RACUV'></sub></form><legend id='RACUV'></legend><bdo id='RACUV'><pre id='RACUV'><center id='RACUV'></center></pre></bdo></b><th id='RACUV'></th></span></q></dt></tr></i><div id='RACUV'><tfoot id='RACUV'></tfoot><dl id='RACUV'><fieldset id='RACUV'></fieldset></dl></div>

                        <small id='RACUV'></small><noframes id='RACUV'>

                          <legend id='RACUV'><style id='RACUV'><dir id='RACUV'><q id='RACUV'></q></dir></style></legend>