当前位置:Gxlcms > PHP教程 > PHP写入文件实现技巧分享_PHP教程

PHP写入文件实现技巧分享_PHP教程

时间:2021-07-01 10:21:17 帮助过:20人阅读

我们知道,在

PHP写入文件判断是否能被写:

< ?php

  1. $file = 'dirlist.php';
  2. if (is_writable($file)
    == false) {
  3. die("我是鸡毛,我不能");
  4. }
  5. ?>

能写了的话可以使用file_put_contents函数实现PHP写入文件:

  1. < ?php
  2. $file = 'dirlist.php';
  3. if (is_writable($file) == false) {
  4. die('我是鸡毛,我不能');
  5. }
  6. $data = '我是可鄙,我想要';
  7. file_put_contents ($file, $data);
  8. ?>

file_put_contents函数在php5中新引进的函数(不知道存在的话用function_exists函数先判断一下)低版本的php无法使用,可以使用如下方式实现PHP写入文件:

  1. $f = fopen($file, 'w');
  2. fwrite($f, $data);
  3. fclose($f);


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445975.htmlTechArticle我们知道,在 PHP写入文件判断是否能被写: ?php $ file = 'dirlist.php' ; if(is_writable($file) ==false){ die(我是鸡毛,我不能); } ? 能写了的话可以使用...

人气教程排行