TotallyI totally agree with the accepted answer,
butbut I would suggest thatto do alittlea little bit more than just playing around with file namethe filename. You should re-compress the original/uploaded file with phpPHP using GD or Imagick and use the new image. This way, you destroy any injected code (well toto be honest, 90% of the timestime, there are ways to make the code survive the compression, but its alotit's a lot of work).
Also
Also, you could use .htaccess files to prevent the upload directory running phpPHP code (iI don't know about IIS and there is probably an equivalent .webconfig ).
<FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> thisThis way, the uploaded file will be executed only if the "final extension" is phpis PHP, so image.php.jpg will not be executed
some resources:.
a nice article about file uploads Some resources: