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?
<?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;
}
?>