title: Save to server side file from PHP via Javascript
body: <p>I am trying to save a json string from a javascript file to a local file on the server using PHP, however, my json file is not being modified at all.
  Here is my Javascript:</p>
  
  <pre><code>function saveToFile(data){
    jsonString = JSON.stringify(data);
    $.ajax({
      url: 'php/save.php',
      data : jsonString,
      type: 'POST'
    });
  }
  </code></pre>
  
  <p>Note that jsonString is a valid variable, and i can log it correctly into the console.</p>
  
  <p>Here is my PHP:</p>
  
  <pre><code>&lt;?php
    $data = $_POST['jsonString'];
    $f = fopen("../website-contents.json", "w") or die("fopen failed");
    fwrite($f, $data) or die("fwrite failed");
    fclose($f);
  ?&gt;
  </code></pre>
  
  <p>Note that even tests trying to save "Hello World" to "test.txt" don't work, or through errors.</p>
  
  <p>Finally, here is my folder structure:
  <img src="https://i.stack.imgur.com/0R8bt.png" alt="enter image description here"></p>