title: PHP fwrite() not working
body: <p>I'm writing a function in php, client side I have a canvas image which I use toDataUrl() along with a file name to save the image on the server. The here's the code:</p>
  
  <pre><code>&lt;?php
    $imageData=$GLOBALS['HTTP_RAW_POST_DATA'];
    $data = json_decode($imageData, true);
  
    $file = $data["file"];
    $image = $data["data"];
  
    $filteredData=substr($image, strpos($image, ",")+1);
    $unencodedData=base64_decode($filteredData);
  
    $fp = fopen( 'image/' . $file , 'wb' );
    fwrite( $fp, $unencodedData);
    fclose( $fp );
  ?&gt;
  </code></pre>
  
  <p>The thing is that this code works. And for two out of three of the pages I used it on it works fine. The problem is when I copy and pasted it a third time to implement it again, for some reason the file is made on the server except that no data get's written into the file. I don't think it's a problem client side because I write in a debug alert message in the javascript and a debug echo into the PHP and both are able to print out the data fine. I made this short debug file:</p>
  
  <pre><code>&lt;?php
  $fp = fopen('data.txt', 'wb');
  if(is_writable('data.txt')){
      echo "file is writable&lt;br&gt;";
  }
  if(fwrite($fp, 'test') == FALSE){
      echo "failed to write data&lt;br&gt;";
  }
  fclose($fp);
  ?&gt;
  </code></pre>
  
  <p>And the output is</p>
  
  <pre><code>file is writable
  failed to write data
  </code></pre>
  
  <p>I've tried using chmod and setting everything, the folder, the text file before I write to it to 0777 and I still get the same result; the file is made but no data is written into it. Is there anything I'm missing or any other approaches that might help. I haven't found anything on google and am still baffled as to why the same code worked exactly as expected twice before suddenly stopping for no apparent reason. </p>
  
  <p>Thanks in advance. </p>