[ nepoverljiv @ 02.02.2016. 19:39 ] @
Zdravo,

Da li neko moze da mi pomogne oko upload slika ili nekog dokumenta na dropbox iz aplikacije uradjene u codeigniteru? Pravi mi problem path i logovanja. Nasao sam ovaj dropbox api, ali kao sto rekoh ne znam to da povezem sa upload fajlovima koji vrsim na localhostu.

Je l' moze neka pomoc?

Hvala unapred
[ nepoverljiv @ 03.02.2016. 18:45 ] @
Da li neko ima ideju koji je path, posto mi ova skripta radi, i imam stranicu koja mi radi upload u localhost folder, samo jos ova dva da spojim? :/
[ nepoverljiv @ 04.02.2016. 21:36 ] @
Kada pozovem funkciju za upload fajla u dropbox folder dobijem sledecu gresku:


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

Deo koda iz biblioteke za curl je:

Code:

    private function _connect($url, $header, $request, $postdata = false, $destination = false)
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
        curl_setopt($ch, CURLOPT_SSLVERSION, 1); // Require TLS
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_CAINFO, __DIR__."/certs/trusted-certs.crt");
        curl_setopt($ch, CURLOPT_CAPATH, __DIR__."/certs/");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request);
        curl_setopt($ch, CURLOPT_HTTPHEADER, explode(self::LINE_END, $header));
        curl_setopt($ch, CURLINFO_HEADER_OUT, true);

        if(is_array($postdata))
        {
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
        }
        
        $response = curl_exec($ch);
        
        if(self::DEBUG)
        {
            error_log(print_r(curl_getinfo($ch), true));
            error_log($response);
        }
        
        $code = curl_getinfo($ch, CURLINFO_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;
    }


Da li neko moze oko ovog da mi pomogne?
[ Tpojka @ 05.02.2016. 00:56 ] @
Pogledaj ovaj video sa upotrebom CURLFile klase, pa probaj shodno izmijeniti vlastiti kod.
CI3 koristi composer & packages, pa se moze upotrijebiti zvanican Dropbox API PHP kod.
[ nepoverljiv @ 05.02.2016. 19:26 ] @
Koliko sam provalio curl funkcija nije dozvoljena od PHP 5.5 nego se koristi cURLFile funkcija. E sad ja ne znam kako to da primenim :/.

[Ovu poruku je menjao nepoverljiv dana 05.02.2016. u 21:12 GMT+1]
[ nepoverljiv @ 06.02.2016. 10:20 ] @
Napokon sam se snasao kako da odradim upload u dropbox. E sad imam jedan problemcic, kako da podelim taj fajl u kontroler i view posto koristim codeigniter.

Da li neko moze da mi objasni kako ovo da uradim, kod koji radi je sledeci:

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