fix the 

should change to 
$filename .= '_' . $part;

for example:
I upload an image, 
the *original filename* is `254.JPG.jpg.140F3_0S.235.jpg`
the *uploaded filename* is`254.JPG.jpg.140F3_0S_.235_.jpg`
the filename *most of us* really want is `254_JPG_jpg_140F3_0S_235.jpg` or `254.JPG.jpg_140F3_0S_235.jpg`

My suggestion is change the code to

   $filename .= '_' . $part;