Reputation: 119
I want getting into the location of files which is in dropbox api.
I want to assign the value in detailsArray
if the folder have any file assign it. If it is folder then go inside folder and get that file. I want to assign the values of all files which is inside the apps folder and also that files which are inside in the apps folder.
PHP CODE
public function access_account($p)
{
if($p == '/')
{
$curl = curl_init( 'https://api.dropbox.com/1/metadata/auto');
}
else
{
$curl = curl_init( 'https://api.dropbox.com/1/metadata/auto'.$p);
}
$headers = array('Authorization: Bearer xxxx');
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);
$auth = json_decode(curl_exec( $curl ) );
//echo '<pre>'; print_r($auth); echo '</pre>'; exit();
return $auth;
//print_r($auth);echo '</pre>';
}
public function get_folders()
{
$p = "/";
$result = $this->access_account($p);
//echo '<pre>'; print_r($result);'</pre>'; exit();
foreach($result->contents as $folders)
{
if($folders->is_dir == 1)
{
$p = $folders->path;
$result = $this->access_account($p);
//echo '<pre>'; print_r($result);'</pre>'; exit();
}
else
{
$this->detailsArray[$this->counter]['path'] = $folders->path;
$this->detailsArray[$this->counter]['modified'] = $folders->modified;
$this->detailsArray[$this->counter]['size'] = $folders->size;
$this->counter++;
//echo "<pre>"; print_r($this->detailsArray); exit;
}
}
echo "<pre>"; print_r($this->detailsArray); exit;
}
Upvotes: 2
Views: 334
Reputation: 119
Actually we have to put variable $p and $counter as global and update $this->p,$this->counter after the loop ends
public function access_account($auth_key,$p)
{
if($this->p == '/')
{
$curl = curl_init( 'https://api.dropbox.com/1/metadata/auto');
}
else
{
$curl = curl_init( 'https://api.dropbox.com/1/metadata/dropbox'.$this->p);
}
$headers = array('Authorization: Bearer '.$auth_key );
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);
$auth = json_decode(curl_exec( $curl ) );
return $auth;
}
public function get_folders()
{
$result = $this->dropbox($auth_key,$this->p);
//echo '<pre>'; print_r($result); echo '</pre>';exit();
foreach($result->contents as $folders)
{
if($folders->is_dir == 1)
{
$this->p= $folders->path;
$this->access_account($auth_key,$this->p);
}
else
{
$this->detailsArray[$this->counter]['path'] = $folders->path;
$this->detailsArray[$this->counter]['modified'] = $folders->modified;
$this->detailsArray[$this->counter]['size'] = $folders->size;
$this->counter++;
}
}
$this->counter = 0;
$this->p = '/';
//echo '<pre>';print_r($this->detailsArray); exit();
return $this->detailsArray;
}
Upvotes: 1