title: PHP image file created with file_put_contents() is corrupted
body: <p>I'm writing image files from a base64 encoded string with a php webservice in this very same folder using <code>file_put_contents()</code>.
  Here is the writing part [PHP]:</p>
  
  <pre><code>$data = base64_decode( $datastring );
  $res = file_put_contents( $path, $data );
  $resultf = array();
  $resultf["request"] = "setpic";
  $resultf["result"] = strval($res);
  $this-&gt;sendResponse(200, json_encode($resultf));
  </code></pre>
  
  <p>And the reading part follows [PHP]:</p>
  
  <pre><code>$datastring = file_get_contents( $path );
  $data = base64_encode( $datastring );
  $resultf["request"] = "getpic";
  $result0 = array();
  $result0["path"] = $path;
  $result0["data"] = $data;
  $resultf["result"] = $result0;
  $this-&gt;sendResponse(200, json_encode($resultf));
  </code></pre>
  
  <p>The two <code>$path</code> are correct.</p>
  
  <p>Nevertheless although <strong>the files are "correctly" created</strong> (I can see them with <code>ssh</code> with a size of approx. 9kB), 
  if I <code>scp</code> the image files they appear to have a width and height of 0, ie a <strong>corrupted image file</strong> I presume.
  If I try to load them using XCode in my iOS app, I get the following error:</p>
  
  <pre><code>ImageIO: &lt;ERROR&gt;  JPEG Corrupt JPEG data: 75 extraneous bytes before marker 0xdb
  </code></pre>
  
  <p>Please note that containing folders have 777 permissions, same user/group than the php webservice accessing them form a parent folder. <strong>This method worked until I unfortunately changed the owner of the root folder.</strong></p>
  
  <p>Thanks a lot for your help.</p>