title: How to fix "getimagesize(): Read error!" in PHP
body: <p>I want to upload images to a server using ajax and php.</p>
  
  <p>On client-side i hava the following code:</p>
  
  <pre><code>var reader = new FileReader();
  reader.readAsDataURL(file, 'UTF-8');
  reader.onload = function (event) {
      var result = event.target.result;
      $.ajax({    
      type: "POST",
      url: "url", 
      data: { 
         data: result, 
         name: file.name,
         mimeType: file.type
      }
     });
   };
  </code></pre>
  
  <p>On server-side my code looks like the following:</p>
  
  <pre><code> $path = 'somehow/'
   $fp = fopen( $path . $_POST['name'], 'w');
      $data = explode( ',', $_POST['data'] );
      fwrite($fp, base64_decode( $data[ 1 ] ));
      fclose($fp);
      chmod($path . $_POST['name'], 7777);
  
      list($width, $height) = getimagesize($path . $_POST['name']);
  </code></pre>
  
  <p>Now the method "getimagesize" always runs into an error "getimagesize(): Read error!"</p>
  
  <p>Does anybody know, why this happens? When i look into the filesystem on the server the file 'FILENAME.JPG' exists ...</p>