Codeigniter 中的 Dropbox API 访问文件夹内的文件?
Dropbox API in Codiegniter Accessing files inside folders?
我想进入保管箱 api 中文件的位置。
如果文件夹有任何文件分配,我想在 detailsArray
中分配值。如果它是文件夹,则进入文件夹并获取该文件。我想为 apps 文件夹内的所有文件以及 apps 文件夹内的文件分配值。
PHP 代码
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;
}
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;
}
我想进入保管箱 api 中文件的位置。
如果文件夹有任何文件分配,我想在 detailsArray
中分配值。如果它是文件夹,则进入文件夹并获取该文件。我想为 apps 文件夹内的所有文件以及 apps 文件夹内的文件分配值。
PHP 代码
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;
}
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;
}