php写入和读取文件内容

180it 2020-04-05 PM 96℃ 0条
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;
    }
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

php写入和读取文件内容