/** * Add photo * * @param string $file Path of file to upload * @param string $title Title to give to file (defaults to filename) * @param string $summary Description of the file * * @return mixed Data from Google * * @since 12.3 * @throws UnexpectedValueException */ public function upload($file, $title = '', $summary = '') { if ($this->isAuthenticated()) { $title = $title != '' ? $title : File::getName($file); if (!($type = $this->getMIME($file))) { throw new RuntimeException("Inappropriate file type."); } if (!($data = File::read($file))) { throw new RuntimeException("Cannot access file: `{$file}`"); } $xml = new SimpleXMLElement('<entry></entry>'); $xml->addAttribute('xmlns', 'http://www.w3.org/2005/Atom'); $xml->addChild('title', $title); $xml->addChild('summary', $summary); $cat = $xml->addChild('category', ''); $cat->addAttribute('scheme', 'http://schemas.google.com/g/2005#kind'); $cat->addAttribute('term', 'http://schemas.google.com/photos/2007#photo'); $post = "Media multipart posting\n"; $post .= "--END_OF_PART\n"; $post .= "Content-Type: application/atom+xml\n\n"; $post .= $xml->asXML() . "\n"; $post .= "--END_OF_PART\n"; $post .= "Content-Type: {$type}\n\n"; $post .= $data; $jdata = $this->query($this->getLink(), $post, array('GData-Version' => 2, 'Content-Type: multipart/related'), 'post'); return new Photo($this->safeXML($jdata->body), $this->options, $this->auth); } else { return false; } }