Gzipping textarea content with php

Im about 80% through an application that im constructing that downloads/decompress/decodes xml.gz files the fly files from my server and shows the output in a textarea for editing all this part works perfect,

but heres my stumbling block:

After editing i then need to encode/gzcompress the textarea contents by php and have the file offered up for downloading (without the page changing) so my problems are

  1. how to re-encode/gzcompress the edited text
  2. how to offer up for downloading

heres the code i have upto yet which displays the xml

<textarea rows="30" name="rawxml" cols="111" class="outputs" >
<?php
$fh = fopen("datafeed.xml", "r");

$file = file_get_contents("datafeed.xml");
echo $file;
?>
</textarea>
<?php
$content = file_get_contents("$file");
        $coded = base64_encode(gzcompress("$file"));
?>
<p align="center">
<input name="submit" type="submit" value="encode xml" />
</p>
</form>

Im pretty un-experienced in .php (amazed myself i got this far actually) but could do with some pointers for this…thanks

Yes you may or may not write more to make this script workable. You can certainly add php header for downloading the file as gzip format.