Home >Backend Development >PHP Tutorial >PHP writing file implementation skills sharing_PHP tutorial

PHP writing file implementation skills sharing_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:34:231594browse

We know that in

PHP writes the file to determine whether it can be written:

< ?php

  1. $file = 'dirlist.php';
  2. if (is_writable($ file)
    == false) {
  3. die("I am a chicken, I can't");
  4. }
  5. ?>
  6. If you can write, you can use the file_put_contents function to write files in PHP:

    <ol class="dp-xml">
    <li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>$</span><span class="attribute">file</span><span> = </span><span class="attribute-value">'dirlist.php'</span><span>;  </span></li><li class="alt"><span>if (is_writable($file) == false) {  </span></li><li><span>die('我是鸡毛,我不能');  </span></li><li class="alt"><span>}  </span></li><li><span>$</span><span class="attribute">data</span><span> = </span><span class="attribute-value">'我是可鄙,我想要'</span><span>;  </span></li><li class="alt"><span>file_put_contents ($file, $data);  </span></li><li><span class="tag">?></span><span> </span></span></li>
    <li class="alt"><span> </span></li>
    </ol>

    The file_put_contents function is in php5 The newly introduced function (if you don’t know it exists, use the function_exists function to determine it first) cannot be used in lower versions of PHP. You can use the following method to write files in PHP:

    <ol class="dp-xml">
    <li class="alt"><span><span>$</span><span class="attribute">f</span><span> = </span><span class="attribute-value">fopen</span><span>($file, 'w');  </span></span></li>
    <li><span>fwrite($f, $data);  </span></li>
    <li class="alt"><span>fclose($f);  </span></li>
    </ol>


    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445975.htmlTechArticleWe know that writing a file in PHP determines whether it can be written: ?php $ file = 'dirlist.php' ; if(is_writable($file) ==false){ die(I am a chicken feather, I can’t); } ? If you can write, you can use...
Statement:
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