Home > php教程 > php手册 > PHP进行读写文件操作

PHP进行读写文件操作

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-21 09:06:00
Original
992 people have browsed it

   

function readfromfile($file_name) { //File Reading
    if (file_exists($file_name)) {
        if (PHP_VERSION >= "4.3.0") return file_get_contents($file_name);
        $filenum=fopen($file_name,"r");
        $sizeofit=filesize($file_name);
        if ($sizeofit        @flock($filenum,LOCK_EX);
        $file_data=fread($filenum, $sizeofit);
        fclose($filenum);
        return $file_data;
    } else return '';
}

function writetofile ($filename, $data) { //File Writing
    $filenum=@fopen($filename,"w");
    if (!$filenum) {
        return false;
    }
    flock($filenum,LOCK_EX);
    $file_data=fwrite($filenum,$data);
    fclose($filenum);
    return true;
}
   
?>



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template