Figured it out. The issue was with there being a space in the name of the page. That is why it was working on some pages and not on others.
Here is the fix (it removes any spaces, so "John Smith" becomes "JohnSmith":
.../index.php?title=Special:Upload&wpDestFile={{#replace:{{PAGENAME}}| |}}.jpg