zoukankan      html  css  js  c++  java
  • dirname(__FILE__)

    php中定义了一个很有用的常数,即

    __file__

    这个内定常数是当前php程序的就是完整路径(路径+文件名)。

    即使这个文件被其他文件引用(include或require),__file__始终是它所在文件的完整路径,而不是引用它的那个文件完整路径。

    请看下面例子:
    /home/data/demo/test/a.php


    <?php
    $the_full_name=__FILE__;
    $the_dir=dirname(__FILE__);
    echo $the_full_name; //返回/home/data/demo/test/a.php
    echo $the_dir;            //返回/home/data/demo/test
    ?>

    home/data/demo/b.php


    <?php include "test/a.php";
    echo $the_full_name; //返回/home/data/demo/
    echo $the_dir;            //返回/home/data/demo/test 而不是/home/data/demo/
    ?>

    是test/a.php所在的路径 而不是/home/data/demo/b.php所在的路径

    简单地说:
          __FILE__     返回当前 路径+文件名
          dirname(__FILE__) 返回当前文件路径的 路径部分
          dirname(dirname(__FILE__));得到的是文件上一层目录名(不含最后一个“/”号)

    例如,当前文件是 /home/data/demo/test.php ,则
    __FILE__ 得到的就是完整路径       即 /home/data/demo/test.php ,而
    dirname(__FILE__)得到路径部分   即 /home/data/demo     (后面没有“/”号)

  • 相关阅读:
    Win10 UWP Tile Generator
    Win10 BackgroundTask
    UWP Tiles
    UWP Ad
    Win10 build package error collections
    Win10 八步打通 Nuget 发布打包
    Win10 UI入门 pivot multiable DataTemplate
    Win10 UI入门 导航滑动条 求UWP工作
    UWP Control Toolkit Collections 求UWP工作
    Win10 UI入门 SliderRectangle
  • 原文地址:https://www.cnblogs.com/tdalcn/p/1996286.html
Copyright © 2011-2022 走看看