php写入和读取文件内容

function read_file($filename){
        // $filename = "/usr/local/something.txt";
        $handle = @fopen($filename, "r");//读取二进制文件时,需要将第二个参数设置成'rb'
        //通过filesize获得文件大小,将整个文件一下子读到一个字符串中
        $contents = @fread($handle, filesize ($filename));
        fclose($handle);
        return $contents;
    }

    function write_file($filename,$txt){
        $myfile = fopen($filename, "w") or die("Unable to open file!");
        fwrite($myfile, $txt);
        fclose($myfile);
        return true;
    }

 

直接撸代码

 

posted @ 2018-08-18 12:53  山上小和尚  阅读(194)  评论(0编辑  收藏  举报