Discuz教程网

php文件操作函数

[复制链接]
authicon dly 发表于 2011-1-11 19:33:07 | 显示全部楼层 |阅读模式
  1. /**
  2. * 读文件
  3. +-------------------------------------------------
  4. * @param string $file
  5. * @return string
  6. +-------------------------------------------------
  7. */
  8. function read($file) {
  9. $hd = fopen($file, "r");
  10. $cont = fread($hd, filesize($file));
  11. fclose($hd);
  12. return $cont;
  13. }
  14. /**
  15. * 写文件
  16. +-------------------------------------------------
  17. * @param string $file
  18. * @param string $cont
  19. +-------------------------------------------------
  20. */
  21. function write($file, $cont=\'\', $mode=\'w\') {
  22. $hd = fopen($file, $mode);
  23. fwrite($hd, $cont);
  24. fclose($hd);
  25. }
  26. //创建多重目录
  27. function _mkdir($dir, $mode=0777) {
  28.     if (is_dir($dir) || @mkdir($dir, $mode)) return true;
  29.     if (!_mkdir(dirname($dir), $mode)) return false;
  30.     return @mkdir($dir, $mode);
  31. }
  32. //删除多重目录
  33. function _rmdir ($dir, $self=true) {
  34. if (!is_dir($dir)) return false;
  35. $handle = opendir($dir);
  36. while (($file = readdir($handle)) !== false) {
  37.   if ($file != "." && $file != "..") {
  38.    is_dir("$dir/$file") ? _rmdir("$dir/$file") : unlink("$dir/$file");
  39.   }
  40. }
  41. if ($self && readdir($handle) == false) {
  42.   closedir($handle);
  43.   rmdir($dir);
  44. }
  45. return true;
  46. }
复制代码






上一篇:header中Content-type的种类
下一篇:用php实现汉字转换成拼音
authicon lanyuqing 发表于 2011-6-22 16:00:06 | 显示全部楼层
支持!好东西,拿走了!
authicon TRACYFLYING 发表于 2011-6-26 04:59:56 | 显示全部楼层
看看  好像不错
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-3 01:58

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表