Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Dropbox Upload
#1

Hi,

Isn't anybody helps me to upload file to dropbox with codeigniter?

I did found this http://jimdoescode.blogspot.rs/2011/07/c...x-api.html but didn't help me. Is not explained how to write view, call controller and upload image to dropbox.

Any ideas?

Thanks
Reply
#2

Can anyone help me with this? I suppose I should call some function from library 'dropbox' but I don't know which, how, and what is my path..
Reply
#3

Just anyone can help me to call function in controller for upload and setup?
Reply
#4

I'm not familiar with the Dropbox API so I can't directly help you, but I believe your answer (to your 'I should call some function from library 'dropbox' but I don't know which' question) should be in de Dropbox API documentations.

The site you link to is over 5 year old, I don't think such an outdated site (CI2 is end of line, Sparks is dead, perhaps the Dropbox API has changed in the last 5 year) is a good starting point. Perhaps you should start with some recent plain PHP examples of the Dropbox API, get familiar with it and then ask the question how you can do that with Codeigniter. I think that way you will get more response.
Reply
#5

When I ask in way you said I got answer to see link I wrote in my question Smile
Reply
#6

When I call function for file uploading in dropbox I getting error:

Message: curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead

Part of code for curl from library is:

PHP Code:
private function _connect($url$header$request$postdata false$destination false)
    {
        
$ch curl_init($url);
        
curl_setopt($chCURLOPT_HTTPAUTHCURLAUTH_BASIC ) ;
        
curl_setopt($chCURLOPT_SSLVERSION1); // Require TLS
        
curl_setopt($chCURLOPT_SSL_VERIFYPEERtrue);
        
curl_setopt($chCURLOPT_SSL_VERIFYHOST2);
        
curl_setopt($chCURLOPT_CAINFO__DIR__."/certs/trusted-certs.crt");
        
curl_setopt($chCURLOPT_CAPATH__DIR__."/certs/");
        
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
curl_setopt($chCURLOPT_CUSTOMREQUEST$request);
        
curl_setopt($chCURLOPT_HTTPHEADERexplode(self::LINE_END$header));
        
curl_setopt($chCURLINFO_HEADER_OUTtrue);

        if(
is_array($postdata))
        {
            
curl_setopt($chCURLOPT_POSTtrue);
            
curl_setopt($chCURLOPT_POSTFIELDS$postdata);
        }
       
        
$response curl_exec($ch);
       
        if(
self::DEBUG)
        {
            
error_log(print_r(curl_getinfo($ch), true));
            
error_log($response);
        }
       
        
$code curl_getinfo($chCURLINFO_HTTP_CODE);
        
curl_close($ch);
       
        
//If this is a content request write the file
        
if($destination !== false)
        {
            
//If the response was good then write
            //the file and return true
            
if($code == '200')
            {
                
$fh fopen($destination'w');
                
fwrite($fh$response);
                if(
$fh !== false)
                {
                    
fclose($fh);
                    return 
true;
                }
            }
            
//The response was bad or the file couldn't
            //be written so return false.
            
return false;
        }
        else return 
$response;
    } 

Any ideas?
Reply
#7

I did figure out that is problem with cURL function cause isn't enable in PHP 5.5 and above. Instead of that I should use cURLFile function but I don't know how to manage that. Please help me!
Reply
#8

Finally I figure out how to upload file into dropbox, but now I can't figure out how to manage to split this code to view and controller:

PHP Code:
<?php
 
error_reporting
(E_ALL);
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' => "MY KEY"
    
'app_secret' => "MY SECRET",
    
'app_full_access' => false,
),
'en');



handle_dropbox_auth($dropbox); // see below




// if there is no upload, show the form
if(empty($_FILES['the_upload'])) {
?>
<form enctype="multipart/form-data" method="POST" action="">
<p>
    <label for="file">Upload File</label>
    <input type="file" name="the_upload" />
</p>
<p><input type="submit" name="submit-btn" value="Upload!"></p>
</form>
<?php } else { 

    
$upload_name $_FILES["the_upload"]["name"];
    echo 
"<pre>";
    echo 
"\r\n\r\n<b>Uploading $upload_name:</b>\r\n";
    
$meta $dropbox->UploadFile($_FILES["the_upload"]["tmp_name"], $upload_name);
    
print_r($meta);
    echo 
"\r\n done!";
    echo 
"</pre>";
}




// ================================================================================
// store_token, load_token, delete_token are SAMPLE functions! please replace with your own!
function store_token($token$name)
{
    
file_put_contents("tokens/$name.token"serialize($token));
}

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 handle_dropbox_auth($dropbox)
{
    
// first try to load existing access token
    
$access_token load_token("access");
    if(!empty(
$access_token)) {
        
$dropbox->SetAccessToken($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>");
    }


Can anybody show me how?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB