The best way to do this is likely to be ...
$filename_ext = pathinfo($filename, PATHINFO_EXTENSION);
$filename = preg_replace('/^(.*)\.' . $filename_ext . '$/', '$1_thumb.' . $filename_ext, $filename);
I tried to test it, with $filename = 'path/to/something.jpg';, but the result was path/to/something_thumb.jpg.
, PHP. , PHP ( , ).