专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »PHP教程 » php文件操作:php基本文件操作方法 »正文

php文件操作:php基本文件操作方法

来源: 发布时间:星期三, 2008年9月10日 浏览:372次 评论:0

纯静态站快做好了,也学到了好多.下面将关于php文件操作的一些简单方法和

函数和大家分享一下:

//创建文件夹 function createFolder($path) { if (!file_exists($path)) { createFolder(dirname($path));

mkdir($path, 0777); } } //删除文件夹和文件夹下的所有文件 function deldir($dir) { $dh=opendir($dir); while ($file=readdir($dh)) { if($file!="." && $file!="..") { $fullpath=$dir."/".$file; if(!is_dir($fullpath)) { unlink($fullpath); } else { deldir($fullpath); } } }

closedir($dh); if(rmdir($dir)) { return true; } else { return false; } }

//删除指定的文件

function dir_delete($file) { if(file_exists($file)) { if(is_dir($file)) { $handle =opendir($file); while(false!==($filename=readdir($handle))) { if($filename!="."&&$filename!="..")$this->dir_delete($file."/".$filename); } closedir($handle); rmdir($file); return true; } else { unlink($file); } } }

dir_delete('../upload/pic/2008061111562626.gif');

//打开文件

$fp = fopen ("temp.html","r");

写入文件 $content = fread ($fp,filesize ("temp.html"));

if (is_file ($indexpath)){ @unlink ($indexpath); //若文件已存在,则删除 } $handle = fopen ($indexpath,"w"); //打开文件指针,创建文件 /*   检查文件是否被创建且可写 */ if (!is_writable ($indexpath)){ echo "文件:".$indexpath."不可写,请检查其属性后重试!"; //修改为echo } if (!fwrite ($handle,$content2)){ //将信息写入文件 echo "生成文件".$indexpath."失败!"; //修改为echo } fclose ($handle); //关闭指针 } fclose ($fp);关闭文件

0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: