首页 > Web开发 > 详细

php常见的类库-文件操作类

时间:2015-04-01 23:33:04      阅读:269      评论:0      收藏:0      [点我收藏+]

工作中经常用php操作文件,因此把常用文件操作整理出来:

 1 class hylaz_file{
 2     /**
 3      * Read file
 4      * @param string $pathname
 5      * @return string content
 6      */
 7     public static function read_file($pathname){
 8         return @file_get_contents($pathname);
 9     }
10     /**
11      * Write File
12      * @param string $pathname 文件名称
13      * @param string $data  写入到文件的数据
14      * @param string $md 打开文件模式
15      * @return int bool
16      */
17     public static function  write_file($pathname,$data,$md=‘wb‘){
18         if(!$fp=fopen($pathname,$mode))
19             return false;
20         flock($fp,LOCK_EX);
21         for($result=$written=0,$length=strlen($data),$written<$length;$written+=$result){
22             if(($result=fwrite($fp,substr($data,$written)))===FALSE){
23                 break;
24             }
25         }
26         flock($fp, LOCK_UN);
27         fclose($fp);
28         return is_int($result);
29     }
30 }
 1 class hylaz_file{
 2     /**
 3      * Read file
 4      * @param string $pathname
 5      * @return string content
 6      */
 7     public static function read_file($pathname){
 8         return @file_get_contents($pathname);
 9     }
10     /**
11      * Write File
12      * @param string $pathname 文件名称
13      * @param string $data  写入到文件的数据
14      * @param string $md 打开文件模式
15      * @return int bool
16      */
17     public static function  write_file($pathname,$data,$md=‘wb‘){
18         if(!$fp=fopen($pathname,$mode))
19             return false;
20         flock($fp,LOCK_EX);
21         for($result=$written=0,$length=strlen($data),$written<$length;$written+=$result){
22             if(($result=fwrite($fp,substr($data,$written)))===FALSE){
23                 break;
24             }
25         }
26         flock($fp, LOCK_UN);
27         fclose($fp);
28         return is_int($result);
29     }
30 }

 

php常见的类库-文件操作类

原文:http://www.cnblogs.com/hylaz/p/4385597.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!