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;
    }

直接撸代码

猜你喜欢

转载自www.cnblogs.com/wenhainan/p/9496922.html