Writing to the beginning of the file is highly impractical.
If you file isn't too big and is not used extensively. Than this is what I'd do.
<?
$fp=fopen("yourfile", "r");
$file_data=fread($fp, filesize("yourfile"));
fclose($fp);
Than you open file again
$fp=fopen("yourfile", "w");
This time the whole file will be wiped out.
Than write the information that you wish to be at the top.
$fwrite($fp, "string_to_be_at_the_top");
$fwrite($fp, "\n");
Now write previous data from the file that is stored in the memory.
$fwrite($fp, $file_data);
fclose($fp);
I don't know for sure, but you can simplify
fopen() procedure by doing
$fp=fopen("yourfile", "r+");
Overall it is not a wise thing to do, but use it as you wish,
Di