php常见的类库-文件操作类
工作中经常用php操作文件,因此把常用文件操作整理出来:
class hylaz_file{
/**
* Read file
* @param string $pathname
* @return string content
*/
public static function read_file($pathname){
return @file_get_contents($pathname);
}
/**
* Write File
* @param string $pathname 文件名称
* @param string $data 写入到文件的数据
* @param string $md 打开文件模式
* @return int bool
*/
public static function write_file($pathname,$data,$md='wb'){
if(!$fp=fopen($pathname,$mode))
return false;
flock($fp,LOCK_EX);
for($result=$written=0,$length=strlen($data),$written<$length;$written+=$result){
if(($result=fwrite($fp,substr($data,$written)))===FALSE){
break;
}
}
flock($fp, LOCK_UN);
fclose($fp);
return is_int($result);
}
/**
* 获取文件信息
* @param string path of file
* @param array array or comma separated string of information returned
* @return array
*/
public static function file_info($file,$return_value=array('name', 'server_path', 'size', 'date')){
if(!file_exists($file)){
return false;
}
if(is_string($return_value)){
$return_value=explode(",",$return_value);
}
foreach($return_value as $key){
switch ($key){
case "name":
$fileinfo['name']=basename($path);
break;
case "server_path":
$fileinfo['server_path']=$file;
break;
case 'date':
$fileinfo['date']=filemtime($file);
break;
case 'size':
$fileinfo['size']=filesize($file);
break;
case 'readable':
$fileinfo['readable']=is_readable($file);
break;
case 'writable':
$fileinfo['writable']=is_writable($file);
break;
case 'executable':
$fileinfo['executable']=is_executable($file);
break;
case 'fileperms':
$fileinfo['fileperms']=fileperms($file);
break;
}
}
return $fileinfo;
}
/**
* 获得八进制的权限位
* @param string $perms
* @return string
*/
public static function octal_permissions($perms){
return substr(sprintf("%o",$perms), -3);
}
}
php常见的类库-文件操作类的更多相关文章
- [C#] 常用工具类——文件操作类
/// <para> FilesUpload:工具方法:ASP.NET上传文件的方法</para> /// <para> FileExists:返回文件是否存在&l ...
- 文件操作类CFile
CFile file; CString str1= L"写入文件成功!"; wchar_t *str2; if (!file.Open(L"Hello.txt" ...
- asp.net文件操作类
/** 文件操作类 **/ #region 引用命名空间 using System; using System.Collections.Generic; using System.Text; usin ...
- android 文件操作类简易总结
android 文件操作类(参考链接) http://www.cnblogs.com/menlsh/archive/2013/04/02/2997084.html package com.androi ...
- Ini文件操作类
/// <summary> /// Ini文件操作类 /// </summary> public class Ini { // 声明INI文件的写操作函数 WritePriva ...
- java csv 文件 操作类
一个CSV文件操作类,功能比较齐全: package tool; import java.io.BufferedReader; import java.io.BufferedWriter; impor ...
- Qt5:Qt文件操作类 QFile
在QT中,操作文件一般不使用C++提供的文件操作类 , 因为操作文件的时候,要用到C++提供的 string 类,而在QT中使用的是Qt自己实现的一个string类 QString .在Qt中使用C+ ...
- C# 文件操作类大全
C# 文件操作类大全 时间:2015-01-31 16:04:20 阅读:1724 评论:0 收藏:0 [点我收藏+] 标签: 1.创建文件夹 //usin ...
- Java文件操作类效率对比
前言 众所周知,Java中有多种针对文件的操作类,以面向字节流和字符流可分为两大类,这里以写入为例: 面向字节流的:FileOutputStream 和 BufferedOutputStream 面向 ...
随机推荐
- Scala 实现快速排序和归并排序
def quickSort1(array: Array[Int]): Array[Int] = { def swap(x: Int, y: Int): Unit = { val tmp = array ...
- sed 很棒的介绍
选项与参数:-n :使用安静(silent)模式.在一般 sed 的用法中,所有来自 STDIN 的数据一般都会被列出到终端上.但如果加上 -n 参数后,则只有经过sed 特殊处理的那一行(或者动作) ...
- Oracle 后台进程
一.基本后台进程 1.数据库写入进程(DBWn): 数据库写入程序讲数据库告诉缓存区中的修改块写入数据文件.对于多数系统来说,一个数据库写入程序(DBW0)就已经足够,但是对于 ...
- Hnoi2013题解 bzoj3139~3144
话说好久没写题(解)了.. 先贴份题解:http://wjmzbmr.com/archives/hnoi-2013-%E9%A2%98%E8%A7%A3/(LJ神题解..Lazycal表示看不懂..) ...
- [BZOJ3944]Sum(杜教筛)
3944: Sum Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 6201 Solved: 1606[Submit][Status][Discuss ...
- 什么是EPEL 及 Centos上安装EPEL(转)
什么是EPEL 及 Centos上安装EPEL 转自:http://www.unxmail.com/read.php?67 RHEL以及他的衍生发行版如CentOS.Scientific Linux为 ...
- 每天一个linux命令12之top
top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.下面详细介绍它的使用方法.top是一个动态显示过程,即可以通过用户按键来不断刷新 ...
- [转][译] 分分钟学会一门语言之 Python 篇
Python was created by Guido Van Rossum in the early 90's. It is now one of the most popularlanguages ...
- no such file or directory : 'users/shikx/xxx/xxx/Appirater.m'
删除此处红色的.m文件即可
- Spring.NET的中间数据层(Middle Tier Data Access)——事务管理(Transaction management)
简介 Spring.NET为事务管理提供了一个持久化抽象(consistent abstraction ),其优点如下: 为不同事务API,例如ADO.NET,Enterprise Services, ...