Page tree
Skip to end of metadata
Go to start of metadata

Before you try this code, make sure you have installed PHP cURL,

The sample for FileCloud API "loginguest" , "getfilelist" and "upload" is done using PHP cURL

 

<?php

 function getCurlValue($filen, $mimetype = '') {
        // PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax
        // See: https://wiki.php.net/rfc/curl-file-upload
        if (function_exists('curl_file_create')) { 
            return curl_file_create(realpath($filen), $mimetype, $filen);
        }   
        
        // Use the old style if using an older version of PHP
        $value = '@' . realpath($filen);
        
        return $value;
    }

$cookie_jar = tempnam('/tmp','cookie');
  
// OPTIONS
$username = "USER";
$password = "PASSWORD";
$serverurl = "http://URL";
$pathval = "/SHARED/fcteamfolder/HR/Policies";
$filename = 'helloworld.txt'; // name of the file to upload
$filefullpath = 'helloworld.txt'; // Full path to file to upload 
  
//assign post data
$param = array('userid' => $username,'password' => $password);

$api = "loginguest";
$url= $serverurl."/core/".$api;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$param);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
$data = curl_exec($ch);
curl_close($ch);
 
$xmlstr = new \SimpleXMLElement($data);
$result = $xmlstr->command->result;
if($result == 1)
{
    echo "Profile Logged in Successfully";
         
            // getfilelist api call
            $api = "getfilelist";
            $path = $pathval;
  
            //assign post data
            $param = array('path' =>$path);
 
            $url= $serverurl."/core/".$api;
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
            curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
            $data = curl_exec($ch);
            curl_close($ch);
 
            $xmlstr = new \SimpleXMLElement($data);
            $total = $xmlstr->meta->total;
            if($total == 0)
            {
                echo "</br>"."No of file's in the system";
            }
            else
            {
                echo "</br>"."Total no. of files:".$total;
                $count = 0;
                    foreach ($xmlstr->entry as $file)
                    {
                        echo "</br>".++$count.".".$file->name;
                    }
            }
     
            //upload api call
            $api = "upload";
            $appnamevalue = "explorer";
            $pathvalue = $pathval;
            $offset = '0';
            $complete = '1';
			
			$cfile = getCurlValue($filefullpath);
			$post = array('file_contents' => $cfile);
  
           $url= $serverurl."/core/upload?appname=explorer" . $appnamevalue . '&path=' . $pathvalue . '&offset=0&complete='.$complete.'&filename=' . $filename;
           $ch = curl_init($url);
           curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
           curl_setopt($ch, CURLOPT_POST, 1);
           curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
           curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
           curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
           $data = curl_exec($ch);
           curl_close($ch);
 
 
           if($data = "OK")
           {
               echo "</br>"."File uploaded Successfully";
           }
           else
           {
               echo $data;
           }
}
else
{
    echo "Error:".$xmlstr->command->message;
}
?>
  • No labels