PHP寫入檔案實現技巧分享_PHP教程

來源:互聯網
上載者:User
我們知道,在

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);


http://www.bkjia.com/PHPjc/445975.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445975.htmlTechArticle我們知道,在 PHP寫入檔案判斷是否能被寫: ?php $ file = 'dirlist.php' ; if(is_writable($file) ==false){ die(我是雞毛,我不能); } ? 能寫了的話可以使用...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.