【问题标题】:Dropbox API in Codiegniter Accessing files inside folders?Codeigniter 中的 Dropbox API 访问文件夹内的文件?
【发布时间】:2015-06-13 07:21:56
【问题描述】:

我想进入 Dropbox api 中文件的位置。 如果文件夹有任何文件分配它,我想分配 detailsArray 中的值。如果是文件夹,则进入文件夹并获取该文件。我想分配应用程序文件夹内的所有文件以及应用程序文件夹内的文件的值。

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;   
}

【问题讨论】:

  • 我认为我们应该使用某种类型的递归函数来检索文件夹文件中的所有文件夹文件和文件夹。

标签: codeigniter dropbox


【解决方案1】:

实际上我们必须将变量 $p 和 $counter 作为全局变量并在循环结束后更新 $this->p,$this->counter

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;
}   

【讨论】:

    猜你喜欢
    • 2013-07-15
    • 1970-01-01
    • 2011-08-25
    • 2013-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-21
    • 2023-03-05
    相关资源
    最近更新 更多