Codiegniter中的Dropbox API访问文件夹内的文件? [英] Dropbox API in Codiegniter Accessing files inside folders?

查看:67
本文介绍了Codiegniter中的Dropbox API访问文件夹内的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想进入Dropbox API中文件的位置。
如果文件夹中有任何文件分配给我,我想在 detailsArray 中分配值。如果是文件夹,则进入文件夹并获取该文件。我想分配apps文件夹内所有文件的值,以及apps文件夹内所有文件的值。

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代码

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


推荐答案


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

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

这篇关于Codiegniter中的Dropbox API访问文件夹内的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆