title: How do I change my PHP script to accept only images to upload on a server?
body: <p>I have a simple script to upload images from a mobile app. But this security hole to load other scripts. 
  How can I allow only JPEG and PNG files?</p>
  
  <pre><code>&lt;?php
  $name=$_GET['imgname'];
  
  if ( substr($name, 0, 1) == '/' ) $name = substr($name, 1);
  
  if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
      $fp = fopen( $name,"wb");
      fwrite( $fp, $GLOBALS[ 'HTTP_RAW_POST_DATA' ] );
      fclose( $fp );
  
       echo "filename=".$name;
  }
  ?&gt;
  </code></pre>