Why are spaces being converted to question marks in this script?

FLNAME=$(basename $PAH)

is missing quotes

FLNAME=$(basename "$PAH")

Others are missing quotes too. Make sure you quote all your variables everywhere.