Spaces needs to be percent-escaped. You can change the command to:
file=${TM_FILEPATH#$HOME/Desktop}
open "http://localhost/desktop${file// /%20}"
First we strip the $HOME/Desktop prefix (store the result in $file), then we do a global substitution when using $file.