Use JSON response instead of regular expression
Improve messages and make it DRY
Reduce upload logic by a lot.
Improve indentation on cURL options for readability
Removed curl_setopt in favor of curl_setopt_array and removed unneeded option change
More useful information appears when an error occurs.