create a txt file with ajax and php

create a txt file with ajax and php

Hey everyone,

i want to write a Script which creates a txt file with some user entered variables.
The communication between the script and my HTML Document with ajax works fine.
But i have some problems with the creation of the file.
Maybe someone find a small mistake in my script... 

  1. <?php

  2. <!-- SAVE POSTDATA PART-->

  3. $content = "test without variables";
  4. $savename = "test.txt";
  5. $file = fopen($savename, "w");
  6. fwrite($file, $content);
  7. fclose($file);
  8. echo $savename;

  9. ?>

And the JavaScript Part:

  1.  $("#mybutton").click(function(){
  2.             $.post("generate-txt.php",
  3.                 {postname:name,postplc2:plc},
  4.                 function(data){
  5.                    top.location.href = data;
  6.                 });
  7. });


I always just get a 404 Error, because the Script can't create the file.

Thank you in advance!