douyuan4697 2014-05-08 06:50
浏览 14
已采纳

他用PHP函数在服务器上创建文件

How to Make this script rewrite content in Output Files , Now it's only merge a new content with a previous content (in the same files)

Here is my code

<?php
    $filename = 'test.php';
    $somecontent = "<?php $jdst_xx = 'HELLO'; ?>
";

    // Let's make sure the file exists and is writable first.
    if (is_writable($filename)) {

        // In our example we're opening $filename in append mode.
        // The file pointer is at the bottom of the file hence
        // that's where $somecontent will go when we fwrite() it.
        if (!$handle = fopen($filename, 'a')) {
             echo "Cannot open file ($filename)";
             exit;
        }

        // Write $somecontent to our opened file.
        if (fwrite($handle, $somecontent) === FALSE) {
            echo "Cannot write to file ($filename)";
            exit;
        }

        echo "Success, wrote ($somecontent) to file ($filename)";

        fclose($handle);

    } else {
        echo "The file $filename is not writable";
    }
    ?>
  • 写回答

5条回答 默认 最新

  • dssj88098 2014-05-08 06:53
    关注

    try to change your

    if (!$handle = fopen($filename, 'a')) { // open in append mode
    

    to

    if (!$handle = fopen($filename, 'w')) {  // open in write mode
    

    For more :- http://www.php.net/manual/en/function.fwrite.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 vscode问题请教
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM