title: PHP fopen and fwrite throws no error, but the files aren't written to or created. Why?
body: <p>I am simply trying to pass some information to a PHP script using jquery $.post() and then write that information to a text file.  The post is working just fine.  No errors are thrown, as far as I know...but the files aren't created and when I put the file there it isn't written to.  Am I missing something?  Here's my code. </p>
  
  <p>JavaScript </p>
  
  <pre><code>  var ajaxData = { IGC: JSON.stringify(containerObj), filename: newFilePath };
    $.post( "../php/generateIGC.php", ajaxData, function(data) {
          $('#generated_textarea').val(data)
    })
  </code></pre>
  
  <p>Originally I tried to interpret what was being sent and write it to the file.  </p>
  
  <p>PHP</p>
  
  <pre><code>&lt;?php
    $data = json_decode(stripslashes($_POST['IGC']), true);
    $myFile = $_POST['filename'];
    $handle = fopen($myFile, 'w'); //or die('Cannot open file:  '.$myFile); 
    fwrite($handle,$data);
    fclose($handle);
    echo "File successfully created";
  ?&gt;
  </code></pre>
  
  <p>Then I gave up and just tried to write to a file that I created for testing, and even this won't work.  </p>
  
  <pre><code>&lt;?php
  
    $data = 'dfjlsdkfsdlfkj';
    $handle = fopen('test.txt', 'w'); //or die('Cannot open file:  '.$myFile); 
    fwrite($handle,$data);
    fclose($handle);
  
   ?&gt;
  </code></pre>
  
  <p>I'm not getting any error in the browser, and the post succeeds.  The only indication I have that something isn't working is the file not being written to or created, and when I access (data) I just get a string of the php script.  What am I doing wrong here?</p>
  
  <p>UPDATE:</p>
  
  <p>I changed the php script to this</p>
  
  <pre><code>&lt;?php
   $data = json_decode(stripslashes($_POST['IGC']), true);
   $myFile = $_POST['filename']
   $handle = fopen('test.txt', 'w') or die('Cannot open file:  '.$myFile); 
   fwrite($handle,$data);
   fclose($handle);
   return $data;
   ?&gt;
  </code></pre>
  
  <p>and now I get the error:</p>
  
  <p>kCFErrorDomainCFNetwork error 1.)</p>
  
  <p>Here is the post function if it helps </p>
  
  <pre><code>    function genCode() {
    var path = $('#path_to_image').val();
    var index = path.length
    for (var i = 1; i&lt;=3; i++) {
      index = path.lastIndexOf('/',index-1)
    }
    var fileToCreate = path.substring(path.lastIndexOf('/')+1,path.lastIndexOf('.'))+'.igc'
    var newFilePath = path.substring(0,path.lastIndexOf('.'))+'.igc'
    containerObj["target_container"] = $('#target_container').val();
    containerObj["img_path"] = path.substring(index+1);
    containerObj["img_dims"] = {x: w, y: h};
    containerObj["mode"] = $('#number_of_axes').val();
    containerObj["sd"] = {x1: $('#sd_x1').val(), y1: $('#sd_y1').val(), x2: $('#sd_x2').val(), y2: $('#sd_y2').val()};
    containerObj["number_of_graphs"] = $('#number_of_graphs').val();
    var show_waypoints = false;
    containerObj["show_waypoints"] = false;
    //$('#generated_textarea').val("attachGraph.addGraph(" + JSON.stringify(containerObj, null, '\t') + ");");
    var ajaxData = { IGC: JSON.stringify(containerObj), filename: newFilePath };
   /*   $.ajax({
        type: "POST",
        url: "../php/generateIGC.php",
        data: ajaxData,
        success: function() {
          $('#generated_textarea').val("File created.")
        }
        })
      })
     */ $.post( "../php/generateIGC.php", ajaxData, function(data) {
          $('#generated_textarea').val(data)
      } )
  }
  </code></pre>