Writing a file without overwriting - Php

Write a file

Snippet Code


  
Rate this page :
  [ 0 votes]

When we need to add data without overwriting the existing contents, add fopen($myFile, 'a') instead of giving fopen($myFile, 'w')

<?php $myFile = "mytest.txt"; $fil = fopen($myFile, 'a') or die("can't open file"); $stringData ="hello this is added string"; fwrite($fil, $stringData); fclose($fil); ?>

Tags


Ask Questions

Ask Question