$this->entries = array();
}
- private function sendRequest($uri, $httpMethod, $postData = null, $extraHeaders = null, $isDownload = false, $returnHeaders = false, $isContentXML = true) {
+ private function sendRequest($uri, $httpMethod, $postData = null, $extraHeaders = null, $isDownload = false, $returnHeaders = false, $isContentXML = true, $returnHTTPCode = false) {
$uri = trim($uri);
// create an associative array from each key/value url query param pair.
$params = array();
if ($httpCode <= 308) {
if ($isDownload) {
return $tmpFile;
+ } else if ($returnHTTPCode) {
+ return array('result' => $result, 'code' => $httpCode);
} else {
return $result;
}
$etag = $entry->getAttribute('gd:etag');
$links = $entry->getElementsByTagName('link');
foreach ($links as $link) {
- if ($link->getAttribute('rel') == 'http://schemas.google.com/g/2005#resumable-edit-media') {
+ if ($link->getAttribute('rel') == 'http://schemas.google.com/g/2005#resumable-create-media') {
$uploadUri = $link->getAttribute('href');
break;
}
}
}
$end = $i + $chunkSize - 1;
- $headers = array('Content-Length: '.$chunkSize, 'Content-Type: '.$mimetype, 'Content Range: bytes '.$i.'-'.$end.'/'.$size);
+ $headers = array('Content-Length: '.$chunkSize, 'Content-Type: '.$mimetype, 'Content-Range: bytes '.$i.'-'.$end.'/'.$size);
$postData = fread($handle, $chunkSize);
- $result = $this->sendRequest($uploadUri, 'PUT', $postData, $headers, false, true, false);
- if ($result) {
- // Get next location to upload file chunk
- if (preg_match('@^Location: (.*)$@m', $result, $matches)) {
+ $result = $this->sendRequest($uploadUri, 'PUT', $postData, $headers, false, true, false, true);
+ if ($result['code'] == '308') {
+ if (preg_match('@^Location: (.*)$@m', $result['result'], $matches)) {
+ // Get next location to upload file chunk
$uploadUri = trim($matches[1]);
}
$i += $chunkSize;