time()函数,dirname(__FILE__) 的使用总结
time()函数将返回从1970-1-1 0:0:0到当前时间的秒数。(整型)
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 (后面没有“/”号)
time()函数,dirname(__FILE__) 的使用总结的更多相关文章
- Python os.path.dirname(__file__) 与 Python os.path.abspath(__file__) 与 os.system() 函数
Python os.path.dirname(__file__) 与 Python os.path.abspath(__file__) 的区别 os.path.abspath(__file__)返回 ...
- ****php:require_once(dirname(__FILE__)."/./config_uc.php");
Q:麻烦清楚地讲解一下这句的意思,具体路径是怎样的,这个文解在 根目录,如果我想放在根目录下的tieba文件夹里,应该怎么修改/./ 这个是表示什么? A: require_once(dirname( ...
- substr(dirname(__FILE__))
这是discuz中定义论坛安装根目录的一个常量.现在我们就来分析一下这个很简单但是非常实用的常量. define('DISCUZ_ROOT', substr(dirname(__FILE__) ...
- PHP中define()和dirname(__FILE__)
1,define() 函数定义一个常量.常量类似变量,不同之处在于: (1)在设定以后,常量的值无法更改 (2)常量名不需要开头的美元符号 ($) (3)作用域不影响对常量的访问 (4)常量值只能是字 ...
- Python os.path.dirname(__file__) os.path.join(str,str)
Python os.path.dirname(__file__) Python os.path.join(str,str) (1).当"print os.path.dirname(__f ...
- os.path.dirname(__file__)使用
os.path.dirname(__file__)使用 该测试脚本所在的位置:D:\第1层\第2层\第3层\第4层\第5层\test11.py test11.py import os #该文件所在位置 ...
- dirname(__FILE__)
dirname() 函数返回路径中的目录部分. __FILE__ :被称为PHP魔术常量,返回当前执行PHP脚本的完整路径和文件名,包含一个绝对路径 dirname(__FILE__) 函数返回的是脚 ...
- Python——os.path.dirname(__file__) 与 os.path.join(str,str)
Python os.path.dirname(__file__) Python os.path.join(str,str) (1).当"print os.path.dirname(__f ...
- PHP获取绝对路径dirname(__FILE__)和__DIR__比较
我们都知道,要获取当前PHP脚本所在目录的绝对路径,dirname(__FILE__) 和 __DIR__都可以实现.那么什么情况下用 dirname(__FILE__),什么情况下用 __DIR__ ...
随机推荐
- C语言中qsort函数用法
C语言中qsort函数用法-示例分析 本文实例汇总介绍了C语言中qsort函数用法,包括针对各种数据类型参数的排序,非常具有实用价值非常具有实用价值. 分享给大家供大家参考.C语言中的qsort ...
- Rendering Paths
渲染路径 Rendering Paths http://game.ceeger.com/Manual/RenderingPaths.html 延迟光照渲染路径的细节 Deferred Lighting ...
- Database Initialization Strategies in Code-First:
You already created a database after running your Code-First application the first time, but what ab ...
- Python操作Redis、Memcache、RabbitMQ、SQLAlchemy
Python操作 Redis.Memcache.RabbitMQ.SQLAlchemy redis介绍:redis是一个开源的,先进的KEY-VALUE存储,它通常被称为数据结构服务器,因为键可以包含 ...
- OC-类方法
类方法 1. 基本概念 直接可以用类名来执行的方法(类本身会在内存中占据存储空间,里面有类\对象方法列表) 2. 类方法和对象方法对比 1) 对象方法 以减号-开头 只能让对象调用,没有对象,这个方 ...
- yii2的urlManager配置
网址伪静态是一个非常常用的网站需求,Yii2可以非常简单地进行配置. 首先,在配置文件config/main.php的'components' 段中,加入如下设置:'urlManager'=>a ...
- ES6箭头函数
1. 无参数 var sum = () => 1 + 2; // 等同于: var sum = function() { return 1 + 2; } 2. 返回单个值 var reflect ...
- centos 安装 svn-1.9.4
wget http://mirrors.cnnic.cn/apache/subversion/subversion-1.9.4.tar.gzwget http://mirror.bit.edu.cn/ ...
- 怎样让Oracle支持中文? 语言_地域.字符集
暂时不涉及数据库业务,但是今天入库的时候中文入库报错,考虑可能是字体不支持,留待备用. 来源:Linux社区 作者:robertkun 语言_地域.字符集SIMPLIFIED CHINESE_CHI ...
- word中替换被批注的正文的值
word中替换被批注的正文的值 word批注winform替换值正文 try { Word.Document docum ...