title: Smugmug uploading image API v2 using PHP & Curl
body: <p>Im trying to upload an image to Smugmug using the Upload API v2.
  I've been trying for quite a time but it wont work.
  This is what i've came up with so far.</p>
  
  <p>When i run the script the response is as follows:</p>
  
  <pre><code>HTTP/1.1 100 Continue HTTP/1.1 200 OK Cache-Control: private, no-store, no-cache, max-age=1, must-revalidate Content-Type: text/xml; charset=utf-8 Date: Tue, 07 Jul 2015 14:18:50 GMT Edge-Control: no-store Expires: Tue, 07 Jul 2015 14:18:50 GMT Server: nginx X-Powered-By: SmugMug/1.0 X-SmugMug-Hiring: How to love what you do: http://www.smugmug.com/jobs/ X-SmugMug-Values: 1/4 - Thrill your customers Content-Length: 38 Connection: keep-alive
  </code></pre>
  
  <p>But the file isn't uploaded..
  Do you see anything wrong with the code?</p>
  
  <pre><code>    include_once("oauth/OAuth.php");
      include_once("constants.php");
  
      $access_token = '***';
      $access_token_secret = '***';
  
      $consumer = new OAuthConsumer(API_KEY, API_KEY_SECRET);
      $signature_method = new OAuthSignatureMethod_PLAINTEXT;
  
      $token = new OAuthToken($access_token, $access_token_secret);
  
      $req_token = OAuthRequest::from_consumer_and_token($consumer, $token, "POST", 'http://upload.smugmug.com');
      $req_token-&gt;sign_request($signature_method, $consumer, $token);
      $parameters = $req_token-&gt;get_parameters();
  
      $path = 'image.png';
      $type = pathinfo($path, PATHINFO_EXTENSION);
      $data = file_get_contents($path);
      $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
  
      $finfo = finfo_open(FILEINFO_MIME_TYPE);
      $mime = finfo_file($finfo, $path);
      finfo_close($finfo);
  
  
      $header[] = 'Authorization: OAuth realm="http://upload.smugmug.com/",
                   oauth_consumer_key='.$parameters['oauth_consumer_key'].',
                   oauth_token='.$parameters['oauth_token'].',
                   oauth_signature_method='.$parameters['oauth_signature_method'].',
                   oauth_signature='.$parameters['oauth_signature'].',
                   oauth_timestamp='.time().',
                   oauth_nonce='.md5(time() . mt_rand()).',
                   oauth_version=1.0';
  
      $body[] = 'Accept: application/json';
      $body[] = 'X-Smug-Version: v2';
      $body[] = 'X-Smug-ResponseType: JSON';
      $body[] = 'X-Smug-AlbumUri: /api/v2/album/******';
      $body[] = 'X-Smug-Filename: image.png';
      $body[] = 'Content-MD5: '.$base64.'';
      $body[] = 'Content-Length: '.filesize($path).'';
      $body[] = 'Content-Type: '.$mime.'';
  
  
  
  
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
      curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_VERBOSE, true);
      curl_setopt($ch, CURLOPT_HEADER, 1);    
      curl_setopt($ch, CURLOPT_URL, 'http://upload.smugmug.com/');    
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $body); 
      curl_error ($ch);
  
  
  
      $result = curl_exec($ch);
  
      print_r($result);
  </code></pre>