Add api/upload.php to allow images to be uploaded.
Fix some bugs according to error.log