[李景山php]thinkphp核心源码注释|File.class.php
来源:互联网 发布:有哪些动画培训班知乎 编辑:程序博客网 时间:2024/06/05 11:13
<?php// +----------------------------------------------------------------------// | TOPThink [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | Copyright (c) 2013 http://topthink.com All rights reserved.// +----------------------------------------------------------------------// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )// +----------------------------------------------------------------------// | Author: liu21st <liu21st@gmail.com>// +----------------------------------------------------------------------namespace Think\Storage\Driver;use Think\Storage;// 本地文件写入存储类//class File extends Storage{ private $contents=array(); /** * 架构函数 * @access public * 清空了 */ public function __construct() { } /** * 文件内容读取 * @access public * @param string $filename 文件名 * @return string */ public function read($filename,$type=''){ return $this->get($filename,'content',$type); }// 外包 读取文件 /** * 文件是否存在 * @access public * @param string $filename 文件名 * @return boolean */ public function has($filename,$type=''){ return is_file($filename); }// 外包 读取文件 /** * 文件删除 * @access public * @param string $filename 文件名 * @return boolean */ public function unlink($filename,$type=''){ unset($this->contents[$filename]); return is_file($filename) ? unlink($filename) : false; }// 重写了系统函数 /** * 文件追加写入 * @access public * @param string $filename 文件名 * @param string $content 追加的文件内容 * @return boolean */ public function append($filename,$content,$type=''){ if(is_file($filename)){ $content = $this->read($filename,$type).$content; } return $this->put($filename,$content,$type); }// 这里 这个 就是读写完成 /** * 加载文件 * @access public * @param string $filename 文件名 * @param array $vars 传入变量 * @return void */ public function load($_filename,$vars=null){ if(!is_null($vars)){ extract($vars, EXTR_OVERWRITE); //EXTR_OVERWRITE - 默认。如果有冲突,则覆盖已有的变量。 } include $_filename; }// 其实 可以 加载到 文件 到 加载了 // 加载变量 /** * 读取文件信息 * @access public * @param string $filename 文件名 * @param string $name 信息名 mtime或者content * @return boolean */ public function get($filename,$name,$type=''){ if(!isset($this->contents[$filename])){ // 电影 if(!is_file($filename)) return false; $this->contents[$filename]=file_get_contents($filename); } $content=$this->contents[$filename]; // 这里的东西 $info = array( // 获取了信息 'mtime' => filemtime($filename), 'content' => $content ); return $info[$name]; }// 返回了 //echo filemtime("test.txt"); //echo "Last modified: ".date("F d Y H:i:s.",filemtime("test.txt")); /** * 文件写入 * @access public * @param string $filename 文件名 * @param string $content 文件内容 * @return boolean */ public function put($filename,$content,$type=''){ $dir = dirname($filename);// 获取路径 if(!is_dir($dir)){// 生成文件 mkdir($dir,0777,true); } if(false === file_put_contents($filename,$content)){ // 获取 了 数据有问题啊 E(L('_STORAGE_WRITE_ERROR_').':'.$filename); }else{ $this->contents[$filename]=$content;// 删除了 问题 return true; } }// 结束}// 总结:// 读、写、删除、追加、加载。
0 0
- [李景山php]thinkphp核心源码注释|File.class.php
- [李景山php]thinkphp核心源码注释|File.class.php
- thinkphp核心源码注释|File.class.php
- [李景山php]thinkphp核心源码注释|View.class.php
- [李景山php]thinkphp核心源码注释|Think.class.php
- [李景山php]thinkphp核心源码注释|Template.class.php
- [李景山php]thinkphp核心源码注释|Storage.class.php
- [李景山php]thinkphp核心源码注释|Route.class.php
- [李景山php]thinkphp核心源码注释|Model.class.php
- [李景山php]thinkphp核心源码注释|Log.class.php
- [李景山php]thinkphp核心源码注释|Hook.class.php
- [李景山php]thinkphp核心源码注释|DB.class.php
- [李景山php]thinkphp核心源码注释|Controller.class.php
- [李景山php]thinkphp核心源码注释|Cache.class.php
- [李景山php]thinkphp核心源码注释|Build.class.php
- [李景山php]thinkphp核心源码注释|App.class.php
- [李景山php]thinkphp核心源码注释|Disaptcher.class.php
- [李景山php]thinkphp核心源码注释|Taglib.class.php
- UIButton超出UIView边界不可点击
- [李景山php]thinkphp核心源码注释|Html.class.php
- 处理某些目录网页不能被calibre解析的方法
- 智能指针使用指南
- 配置python的pandas包
- [李景山php]thinkphp核心源码注释|File.class.php
- APACHE-CXF demo
- 基于海思的H265码流实时传输系统设计
- Bitmap的四种属性,与每种属性对应的大小
- [下界最小流] UNR #1 奇怪的线段树
- mysql workbench 错误 No database selected Select the default DB to be used by double-clicking its nam
- APUE 7-13 longjmp对各类对象的影响
- Android 基于注解的框架
- 解题报告:Lightoj Harmonic Number 打表