php读取文件内容并清空文件

WBOY
Release: 2016-07-25 08:53:44
Original
1763 people have browsed it
  1. //读取文件内容

  2. $fh = fopen($path, "r+");
  3. if( flock($fh, lock_ex) ){//加写锁

  4. $old_content=json_decode(fread($fh,filesize($path)),true);
  5. $old_content=$old_content.$new_content;

  6. ftruncate($fh,0); // 将文件截断到给定的长度
  7. rewind($fh); // 倒回文件指针的位置
  8. fwrite($fh,json_encode($old_content));
  9. // @chmod($path,0644);
  10. flock($fh, lock_un); //解锁
  11. }

  12. fclose($fh);
复制代码


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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!