# Append text to the top of a file \[PHP\]

**URL:** <https://forum.kirupa.com/t/append-text-to-the-top-of-a-file-php/141372>\
**Category:** Uncategorized\
**Created:** [March 19, 2005, 12:02pm UTC](https://forum.kirupa.com/t/append-text-to-the-top-of-a-file-php/141372 "2005-03-19T12:02:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveMania](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@DaveMania](https://forum.kirupa.com/u/DaveMania)\
**Post date:** [March 19, 2005, 12:02pm UTC](https://forum.kirupa.com/t/append-text-to-the-top-of-a-file-php/141372/1 "2005-03-19T12:02:42Z")

</div>

how can i append text the the top of a .txt file?  
I’ve set up a post a view of the text file but the way i’m laying it out is that when I post it needs to be placed at the top of the document.  
here’s the code:

```php
<?php
$filename = $_POST["filename"];
$header = $_POST["header"];
$content = $_POST["content"];
$footer = $_POST["footer"];

$data = fopen($filename, "a");

fwrite($data,$header);
fwrite($data,"|");
fwrite($data,$content);
fwrite($data,"|");
fwrite($data,$footer);
fwrite($data,"
");

fclose($data);

echo '
Done!<br>Click <a href="view.php">here</a> to view the file.
';

?>

```

I just need to be able to post to the top. nothing simple but i’m a n00b so in patronising terms would be good 🙂
