La stringa:

".str_replace("_", "-", ".jpg", " ",$filename)."

mi funziona, è scritta nel modo corretto?
Perchè hai aggiunto l'altra?