First I checked my PHP settings in DreamHost control panel. PHP was not set to run as CGI, so I changed it. I waited 30 minutes, then tried the PHP file upload script again, but the result was the same.
Next I tried renaming the script file extension to PCGI. This fixed the problem immediately.
A couple of hours later, I renamed the file back to PHP. The script still worked, so obviously changing PHP to run as CGI had the desired effect.
Thanks all of you for your help.