duagfgfn1981 2014-06-19 06:45
浏览 30
已采纳

如何使用PHP在Dropbox上创建文件夹

I want to create the folder dynamically on dropbox and i am using the below code but it gives me error please help me

function CreateFolder($path) {
    return $this->apiCall("fileops/create_folder", "POST", array('root'=> $this->rootPath, 'path' => $path));
}
$x = 'test';    
CreateFolder($x);

But it gives me the error

Parse error: syntax error, unexpected '$x' (T_VARIABLE), expecting function (T_FUNCTION) in /home/stsgbnet/public_html/stockpile/DropPHP-master/DropboxClient.php on line 451

My complete code is here

http://pastebin.com/HnPvV4b0

  • 写回答

1条回答 默认 最新

  • douzen1880 2014-06-19 06:54
    关注

    Since CreateFolder function seems to be in a class ($this->apiCall points to that), $x should be encapsulated in a function (that is the error that's shown). So to make it work, just call it from outside class.

    You are using DropboxClient.php so following sample.php from this package your create a php file and put the following code on it:

    <?php
    
    // these 2 lines are just to enable error reporting and disable output buffering (don't include this in you application!)
    error_reporting(E_ALL);
    enable_implicit_flush();
    // -- end of unneeded stuff
    
    // if there are many files in your Dropbox it can take some time, so disable the max. execution time
    set_time_limit(0);
    
    require_once("DropboxClient.php");
    
    // you have to create an app at https://www.dropbox.com/developers/apps and enter details below:
    $dropbox = new DropboxClient(array(
        'app_key' => "", 
        'app_secret' => "",
        'app_full_access' => false,
    ),'en');
    
    
    // first try to load existing access token
    $access_token = load_token("access");
    if(!empty($access_token)) {
        $dropbox->SetAccessToken($access_token);
        echo "loaded access token:";
        print_r($access_token);
    }
    elseif(!empty($_GET['auth_callback'])) // are we coming from dropbox's auth page?
    {
        // then load our previosly created request token
        $request_token = load_token($_GET['oauth_token']);
        if(empty($request_token)) die('Request token not found!');
    
        // get & store access token, the request token is not needed anymore
        $access_token = $dropbox->GetAccessToken($request_token);   
        store_token($access_token, "access");
        delete_token($_GET['oauth_token']);
    }
    
    // checks if access token is required
    if(!$dropbox->IsAuthorized())
    {
        // redirect user to dropbox auth page
        $return_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?auth_callback=1";
        $auth_url = $dropbox->BuildAuthorizeUrl($return_url);
        $request_token = $dropbox->GetRequestToken();
        store_token($request_token, $request_token['t']);
        die("Authentication required. <a href='$auth_url'>Click here.</a>");
    }
    
    echo "<pre>";
    echo "<b>Account:</b>
    ";
    print_r($dropbox->GetAccountInfo());
    
    // Here will create the folder.
    $dropbox->CreateFolder('test');
    
    
    function store_token($token, $name)
    {
        if(!file_put_contents("tokens/$name.token", serialize($token)))
            die('<br />Could not store token! <b>Make sure that the directory `tokens` exists and is writable!</b>');
    }
    
    function load_token($name)
    {
        if(!file_exists("tokens/$name.token")) return null;
        return @unserialize(@file_get_contents("tokens/$name.token"));
    }
    
    function delete_token($name)
    {
        @unlink("tokens/$name.token");
    }
    
    function enable_implicit_flush()
    {
        @apache_setenv('no-gzip', 1);
        @ini_set('zlib.output_compression', 0);
        @ini_set('implicit_flush', 1);
        for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
        ob_implicit_flush(1);
        echo "<!-- ".str_repeat(' ', 2000)." -->";
    }
    
    ?>
    

    Hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用lstm来预测股票价格
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上