I have modified the Reference Application: PHP File System Manager upload.php file and the IMFS.php class file as seen below. I keep getting a "Couldn't resolve host 'http:'" error when I run the code. It seems to get stuck on the getUploadNode function. Can someone tell me what I am doing wrong.
Page I'm doing the upload on - Test.php
<?php
require_once "IMFS.php";
require_once "Authentication.php";
$imfs = new IMFS();
$path = "upload/";
$file = "D:\Websites\nirvanix\test_c\test.mpg";
// Get a sessionToken
$auth = new Authentication();
$sessionToken = $auth->Login("user", "password", "key");
echo $sessionToken;
// Retrieve the upload node with the upload access token.
// this is passed on to the client so they can authenticate with an IP Address
// that is different from the servers that was used to login.
$uploadNode = $imfs->GetUploadNode($sessionToken);
// retrieve the accessToken
$accessToken = $uploadNode->GetUploadNode->AccessToken;
// get server to upload to
$ipAddress = $uploadNode->GetUploadNode->IPAddress;
$request_uploadfile = "http://$ipaddress/Upload.ashx?uploadToken=$accessToken&destFolderPath=$path";
$uploadFile = $imfs->postFile($request_uploadfile, $file);
?>
Modified IMFS.php File
<?php
/****
Author: Nirvanix
Date: 8-21-2007
Website: http://developer.nirvanix.com/
License: See http://developer.nirvanix.com/content/license.aspx
Limited Permissive License
This license governs use of the accompanying software. If you use the software,
you accept this license. If you do not accept the license, do not use or distribute
the software.
****/
require_once "RestUtils.php";
require_once "Config.php";
class IMFS
{
//Copies one or more folders to a destination folder
public function CopyFiles($sessionToken, $srcFilePaths, $destFilePath)
{
global $DEBUG;
global $IMFSHOST;
// Set the parameters
$filePathParams = 'sessionToken=' . $sessionToken . '&';
$filePathParams = $filePathParams. 'destFolderPath=' . $destFilePath . '&';
// loop through each source file path building the arrray.
foreach ($srcFilePaths as $filePath)
{
$filePathParams = $filePathParams . 'srcFilePath=' . $filePath . '&';
}
// retrieve from the REST interface the response xml.
$xmlstring = curlGet($IMFSHOST . '/ws/IMFS/copyfiles.ashx?' . $filePathParams);
if ($DEBUG)
{
print '<!--CopyFiles: ';
print_r($xmlstring);
print '-->';
}
// turn into an object for easier handling.
$xml = new SimpleXMLElement($xmlstring);
return $xml;
}
//Copies one or more folders to a destination folder
public function CopyFolders($sessionToken, $srcFolderPaths, $destFolderPath)
{
global $DEBUG;
global $IMFSHOST;
// set the parameters.
$folderPathParams = 'sessionToken=' . $sessionToken . '&';
$folderPathParams = $folderPathParams . 'destFolderPath=' . $destFolderPath . '&';
// loop through each source file path building the arrray.
foreach ($srcFolderPaths as $folderPath)
{
$folderPathParams = $folderPathParams . 'srcFolderPath=' . $folderPath . '&';
}
// retrieve from the REST interface the response xml.
$xmlstring = curlGet($IMFSHOST . '/ws/IMFS/copyfolders.ashx?' . $folderPathParams);
if ($DEBUG)
{
print '<!--CopyFolders: ';
print_r($xmlstring);
print '-->';
}
// turn into an object for easier handling.
$xml = new SimpleXMLElement($xmlstring);
return $xml;
}
// Creates one or more folders
public function CreateFolders($sessionToken, $folderPaths)
{
global $DEBUG;
global $IMFSHOST;
// Set the parameters
$folderPathParams = 'sessionToken=' . $sessionToken . '&';
// loop through each source file path building the arrray.
foreach ($folderPaths as $folderPath)
{
$folderPathParams = $folderPathParams . 'folderPath=' . $folderPath . '&';
}
// retrieve from the REST interface the response xml.
$xmlstring = curlGet($IMFSHOST . '/ws/IMFS/createfolders.ashx?' . $folderPathParams);
if ($DEBUG)
{
print '<!--CreateFolders: ';
print_r($xmlstring);
print '-->';
}
// turn into an object for easier handling.
$xml = new SimpleXMLElement($xmlstring);
return $xml;
}
//Deletes one or more files
public function DeleteFiles($sessionToken, $filePaths)
{
global $DEBUG;
global $IMFSHOST;
// Set the parameters
$params = 'sessionToken=' . $sessionToken . '&';
// loop through each source file path building the arrray.
foreach ($filePaths as $filePath)
{
$params = $params . 'filePath=' . $filePath . '&';
}
// retrieve from the REST interface the response xml.
$xmlstring = curlGet($IMFSHOST . '/ws/IMFS/deletefiles.ashx?' . $params);
if ($DEBUG)
{
print '<!--DeleteFiles: ';
print_r($xmlstring);
print '-->';
}
// turn into an object for easier handling.
$xml = new SimpleXMLElement($xmlstring);
return $xml;
}
//Deletes one or more folders
public function DeleteFolders($sessionToken, $folderPaths)
{
global $DEBUG;
global $IMFSHOST;
// Set the parameters
$folderPathParams = 'sessionToken=' . $sessionToken . '&';
// loop through each source file path building the arrray.
foreach ($folderPaths as $folderPath)
{
$folderPathParams = $folderPathParams . 'folderPath=' . $folderPath . '&';
}
// retrieve from the REST interface the response xml.
$xmlstring = curlGet($IMFSHOST . '/ws/IMFS/deletefolders.ashx?' . $folderPathParams);
if ($DEBUG)
{
print '<!--DeleteFolders: ';
print_r($xmlstring);
print '-->';
}
// turn into an object for easier handling.
$xml = new SimpleXMLElement($xmlstring);
return $xml;
}
// Gets the links for an array of files.
public function GetDownloadLinks($sessionToken, $filePaths, $expiration, $restrictedIP = null)
{
global $DEBUG;
global $IMFSHOST;
// Set the parameters
$filePathParams = 'sessionToken=' . $sessionToken . '&';
$filePathParams = $filePathParams . 'expiration=' . $expiration . '&';
$filePathParams = $filePathParams . 'restrictedIP=' . $restrictedIP . '&';
// loop through each source file path building the arrray.
foreach ($filePaths as $filePath)
{
$filePathParams = $filePathParams . 'filePath=' . $filePath . '&';
}
// retrieve from the REST interface the response xml.
$xmlstring = curlGet($IMFSHOST . '/ws/IMFS/GetDownloadLinks.ashx?' . $filePathParams);
if ($DEBUG)
{
print '<!--GetDownloadLinks: ';
print_r($xmlstring);
print '-->';
}
// turn into an object for easier handling.
$xml = new SimpleXMLElement($xmlstring);
return $xml;
}
// Get the node to upload this file to.
// Since this is over the web we have to estimate the sizeBytes since we cannot control
// the client.
public function GetUploadNode($sessionToken)
{
global $DEBUG;
global $IMFSHOST;
// Set the parameters
$params = 'sessionToken=' . $sessionToken . '&';
$params = $params . 'sizeBytes=10000';
// retrieve from the REST interface the response xml.
$xmlstring = curlGet($IMFSHOST . '/ws/IMFS/GetUploadNode.ashx?' . $params);
if ($DEBUG)
{
print '<!--GetUploadNode: ';
print_r($xmlstring);
print '-->';
}
// turn into an object for easier handling.
$xml = new SimpleXMLElement($xmlstring);
return $xml;
}
// Lists the specified folder.
public function ListFolder($sessionToken, $folderPath, $pageNumber, $pageSize, $sortCode, $sortDescending)
{
global $DEBUG;
global $IMFSHOST;
// Set the parameters
$params = 'sessionToken=' . $sessionToken . '&';
$params = $params . 'folderPath=' . $folderPath . '&';
$params = $params . 'pageNumber=' . $pageNumber . '&';
$params = $params . 'pageSize=' . $pageSize . '&';
$params = $params . 'sortCode=' . $sortCode . '&';
$params = $params . 'sortDescending=' . $sortDescending;
// retrieve from the REST interface the response xml.
$xmlstring = curlGet($IMFSHOST . '/ws/IMFS/listfolder.ashx?' . $params);
if ($DEBUG)
{
print '<!--ListFolder: ';
print_r($xmlstring);
print '-->';
}
// turn into an object for easier handling.
$xml = new SimpleXMLElement($xmlstring);
return $xml;
}
//Moves one or more files to a destination folder
public function MoveFiles($sessionToken, $srcFilePaths, $destFolderPath)
{
global $DEBUG;
global $IMFSHOST;
// Set the parameters
$params = 'sessionToken=' . $sessionToken . '&';
$params = $params . 'destFolderPath=' . $destFolderPath . '&';
// loop through each source file path building the arrray.
foreach ($srcFilePaths as $filePath)
{
$params = $params . 'srcFilePath=' . $filePath . '&';
}
// retrieve from the REST interface the response xml.
$xmlstring = curlGet($IMFSHOST . '/ws/IMFS/movefiles.ashx?' . $params);
if ($DEBUG)
{
print '<!--MoveFiles: ';
print_r($xmlstring);
print '-->';
}
// turn into an object for easier handling.
$xml = new SimpleXMLElement($xmlstring);
return $xml;
}
// Moves one or more folders to a destination folder
public function MoveFolders($sessionToken, $srcFolderPaths, $destFolderPath)
{
global $DEBUG;
global $IMFSHOST;
// Set the parameters
$folderPathParams = 'sessionToken=' . $sessionToken . '&';
$folderPathParams = $folderPathParams . 'destFolderPath=' . $destFolderPath . '&';
// loop through each source file path building the arrray.
foreach ($srcFolderPaths as $folderPath)
{
$folderPathParams = $folderPathParams . 'srcFolderPath=' . $folderPath . '&';
}
// retrieve from the REST interface the response xml.
$xmlstring = curlGet($IMFSHOST . '/ws/IMFS/movefolders.ashx?' . $folderPathParams);
if ($DEBUG)
{
print '<!--MoveFolders: ';
print_r($xmlstring);
print '-->';
}
// turn into an object for easier handling.
$xml = new SimpleXMLElement($xmlstring);
return $xml;
}
// Renames a single file
public function RenameFile($sessionToken, $filePath, $newFileName)
{
global $DEBUG;
global $IMFSHOST;
// Set the parameters
$params = 'sessionToken=' . $sessionToken . '&';
$params = $params . 'filePath=' . $filePath . '&';
$params = $params . 'newFileName=' . $newFileName;
// retrieve from the REST interface the response xml.
$xmlstring = curlGet($IMFSHOST . '/ws/IMFS/renamefile.ashx?' . $params);
if ($DEBUG)
{
print '<!--RenameFile: ';
print_r($xmlstring);
print '-->';
}
// turn into an object for easier handling.
$xml = new SimpleXMLElement($xmlstring);
return $xml;
}
// Renames a single folder
public function RenameFolder($sessionToken, $folderPath, $newFolderName)
{
global $DEBUG;
global $IMFSHOST;
// Set the parameters
$folderPathParams = 'sessionToken=' . $sessionToken . '&';
$folderPathParams = $folderPathParams . 'folderPath=' . $folderPath . '&';
$folderPathParams = $folderPathParams . 'newFolderName=' . $newFolderName;
// retrieve from the REST interface the response xml.
$xmlstring = curlGet($IMFSHOST . '/ws/IMFS/renamefolder.ashx?' . $folderPathParams);
if ($DEBUG)
{
print '<!--RenameFolder: ';
print_r($xmlstring);
print '-->';
}
// turn into an object for easier handling.
$xml = new SimpleXMLElement($xmlstring);
return $xml;
}
// Curl method to post a file.
function postFile($restlink, $file, $timeout = 20) {
$crl = curl_init();
if ( !$crl ) return NULL;
// Set the other parameters on the $restlink to simplify this example.
// somefile can be any value that does not conflict with an existing parameter,
// the @$file tells curl to open the file at $file (must be a full path) and stream
// it to the recipient.
$postfields = array(
'somefile'=>"@$file"
);
// Set options
curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($crl, CURLOPT_URL, $restlink);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_POST, 1);
curl_setopt($crl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($crl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($crl, CURLOPT_VERBOSE, 1);
// excute curl request
$result = curl_exec($crl);
// If there was an error print the result.
if (curl_errno($crl)) {
print curl_error($crl);
}
// Close the curl library
curl_close ($crl);
return $result;
}
function transcodeVideo($restlink, $timeout = 20) {
$crl = curl_init();
if ( !$crl ) return NULL;
// Set the other parameters on the $restlink to simplify this example.
// somefile can be any value that does not conflict with an existing parameter,
// the @$file tells curl to open the file at $file (must be a full path) and stream
// it to the recipient.
// Set options
curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($crl, CURLOPT_URL, $restlink);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_POST, 1);
curl_setopt($crl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($crl, CURLOPT_VERBOSE, 1);
// excute curl request
$result = curl_exec($crl);
// If there was an error print the result.
if (curl_errno($crl)) {
print curl_error($crl);
}
// Close the curl library
curl_close ($crl);
return $result;
}
}
?>