码迷,mamicode.com
首页 > Web开发 > 详细

php函数操作文件

时间:2016-08-19 00:49:27      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

<?php
function d_rmdir($dirname) {   //删除非空目录
    if(!is_dir($dirname)) {
        return false;
    }
    $handle = @opendir($dirname);
    while(($file = @readdir($handle)) !== false){
        if($file != . && $file != ..){
            $dir = $dirname . / . $file;
            is_dir($dir) ? d_rmdir($dir) : unlink($dir);
        }
    }
    closedir($handle);
    return rmdir($dirname) ;
}
//   if(unlink("F:/111www/1111111111111/test/test2.php")){    //删除文件
//   if(rmdir("F:/111www/1111111111111/test/222")){           //删除空文件夹
   if(d_rmdir("./111")){
       echo "删除成功";
   }else{
       echo "删除失败";
   }

?>
chmod("/somedir/somefile", 755); //赋权限
$arr = explode("/Application",dirname(__FILE__));
$ordPath = $arr[0]./Public/aj/index.html;
$newPath = $arr[0]./Application/Stage/View/Index/index.$id..html;

$state = copy($ordPath,$newPath);   //拷贝文件
$test = file_get_contents($ordPath);    //获得文件内容
$temp = str_replace(%keywords%,$description, $test);    //替换内容
$isTrue = file_put_contents($newPath, $temp);    //生成文件

 

php函数操作文件

标签:

原文地址:http://www.cnblogs.com/suxiaolong/p/5786020.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!