The following line in fetch_image_info() causes filename corruption if safe mode is turned on:
Content visible to verified customers only.
In Safe Mode, the Filename is $userid-something.ext
This code causes the filename to be rewritten to $userid something.ext and the following code rewrites it to $userid_something.ext
As a result, the filename in DB is still $userid-something.ext, while the file itself is really $userid_something.ext.
So this results in all new images being broken
Please fix this immediately
and provide a script to clean up the mess!