# Save XML file Locally via PHP?

**URL:** <https://forum.kirupa.com/t/save-xml-file-locally-via-php/157644>\
**Category:** programming\
**Created:** [August 3, 2005, 1:52pm UTC](https://forum.kirupa.com/t/save-xml-file-locally-via-php/157644 "2005-08-03T13:52:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MDiddy](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@MDiddy](https://forum.kirupa.com/u/MDiddy)\
**Post date:** [August 3, 2005, 1:52pm UTC](https://forum.kirupa.com/t/save-xml-file-locally-via-php/157644/1 "2005-08-03T13:52:49Z")

</div>

Hello

I made a small Flash Interface for generating a specific XML file. When the user is done, curently they click a button, then a text field is populated with the XML output, then they can copy & paste it into a text file.

I understand that there is a way to pass vars to a php script and have it push a file to the user. Does anyone have an example? I think I’m halfway there with this code:

```php
<?php
$filename = $_GET["filename"];
$bytes = filesize("$file");
header("Content-type: text/xml");
header("Content-disposition: attachment; filename=\"$filename\"");
header("Content-length: $bytes");
//Read the file and output to browser
@readfile($file);
//Code to record the download in database
?>

```

Basically, I have code on the button in flash to getURL this php file, and post the XML as “file” & my desired filename as “filename”. The file saves for the user with the correct filename so I think I’m on the right track, but the file is empty.

What am I missing?

Needless to say, I’ve never really worked with PHP, but I understand it’s syntax is similar to AS. I would really appreciate a brief exmplanation.

Thanks!
