首页 > php文件操作 > php 写入和读取文件函数

php 写入和读取文件函数

//读取文件函数  
<?php
function readfromfile($file_name) {
    if (file_exists($file_name)) {
        $filenum = fopen($file_name, "r");
        flock($filenum, lock_ex);
        $file_data = fread($filenum, filesize($file_name));
        rewind($filenum); //osphp.com.cn
        fclose($filenum);
        return $file_data;
    }
}
?>
//写入文件函数  
<?php
function writetofile($file_name, $data, $method = "w") {
    $filenum = fopen($file_name, $method);
    flock($filenum, lock_ex);
    $file_data = fwrite($filenum, $data);
    fclose($filenum);
    return $file_data;
}
?>


教程地址:http://www.phprm.com/wenjian/fs3108.html

欢迎转载!但请带上文章地址^^

标签:函数 php 写入文件

相关文章

发表留言