diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/Service/Nirvanix/Namespace/Imfs.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/Service/Nirvanix/Namespace/Imfs.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,105 @@ + $filePath, + 'expiration' => $expiration); + $resp = $this->getOptimalUrls($params); + $url = (string)$resp->Download->DownloadURL; + + // download the file + $this->_httpClient->resetParameters(); + $this->_httpClient->setUri($url); + $resp = $this->_httpClient->request(Zend_Http_Client::GET); + + return $resp->getBody(); + } + + /** + * Convenience function to put the contents of a string into + * the Nirvanix IMFS. Analog to PHP's file_put_contents(). + * + * @param string $filePath Remote path and filename + * @param integer $data Data to store in the file + * @param string $mimeType Mime type of data + * @return Zend_Service_Nirvanix_Response + */ + public function putContents($filePath, $data, $mimeType = null) + { + // get storage node for upload + $params = array('sizeBytes' => strlen($data)); + $resp = $this->getStorageNode($params); + $host = (string)$resp->GetStorageNode->UploadHost; + $uploadToken = (string)$resp->GetStorageNode->UploadToken; + + // http upload data into remote file + $this->_httpClient->resetParameters(); + $this->_httpClient->setUri("http://{$host}/Upload.ashx"); + $this->_httpClient->setParameterPost('uploadToken', $uploadToken); + $this->_httpClient->setParameterPost('destFolderPath', str_replace('\\', '/',dirname($filePath))); + $this->_httpClient->setFileUpload(basename($filePath), 'uploadFile', $data, $mimeType); + $response = $this->_httpClient->request(Zend_Http_Client::POST); + + return new Zend_Service_Nirvanix_Response($response->getBody()); + } + + /** + * Convenience function to remove a file from the Nirvanix IMFS. + * Analog to PHP's unlink(). + * + * @param string $filePath Remove path and filename + * @return Zend_Service_Nirvanix_Response + */ + public function unlink($filePath) + { + $params = array('filePath' => $filePath); + return $this->deleteFiles($params); + } + +}