private function upload_photo($args) { if (count($args) >= 1) { $method_args = array_shift($args); } else { $method_args = array(); } $this->options = $args[0]; $this->category = 'upload'; if (TwitPic::mode() == TwitPic_Config::MODE_READONLY) { throw new TwitPicAPIException("Uploading a photo requires an API key and Twitter credentials"); } if (!isset($method_args['message']) || !isset($method_args['media'])) { throw new TwitPicAPIException("Missing required parameter for photo upload"); } if (!is_file($method_args['media']) || !is_readable($method_args['media'])) { throw new TwitPicAPIException("Unable to find or read file"); } $this->format = $this->get_format(); $header = $this->build_header(); $url = "http://api.twitpic.com/2/upload.{$this->format}"; $r = new Http_Request2($url, Http_Request2::METHOD_POST); $r->setHeader('X-Verify-Credentials-Authorization', $header); $r->addPostParameter('key', TwitPic_Config::getAPIKey()); $r->addPostParameter('message', $method_args['message']); $r->addUpload('media', $method_args['media']); $res = $r->send(); if ($res->getStatus() == 200) { if ($this->options['tweet']) { return $this->post_to_twitter($res->getBody()); } else { return $this->respond($res->getBody()); } } else { throw new TwitPicAPIException($res->getBody()); } }