fabi.me

DropPHP – einfacher PHP Dropbox API Client ohne cURL

DropPHP ist eine kompakte PHP Klasse, die eine einfache Schnittstelle zur Dropbox REST API zur Verfügung stellt. Sie bietet Funktionen zum Auflisten, Hoch- und Runterladen von Dateien an ChangeDiva. DropPHP verwendet für HTTPS-Requests die in PHP eingebauten Stream-Wrapper, daher werden keine besonderen PHP Bilbiotheken wie PECL oder cURL benötigt Download FoxPlayer. Es steht unter einer BSD-Lizenz zur Verfügung, hier die GitHub Seite.

DropPHP
DropPHP
master.zip.html
Version: 1.4
12 KiB
16055 Downloads
Details

Funktionen

Die Klasse DropboxClient enthält folgende Funktionen 쯔바이. Bei einem Fehler wird eine DropboxException ausgeworfen, achte daher darauf, dass du die Funktionen in einem try-catch-Block aufrufst! Funktionen dropbox_file/dropbox_path als Parameter haben, akzeptieren diesen als string oder Metadata-Objekt der Datei oder des Ordners Download Internet Explorer 11 file.

GetAccountInfo() Ermittelt Informationen über den Benutzeraccount und gibt sie als Objekt zurück lg intelligent update 다운로드.
GetMetadata($dropbox_path) Ermittelt Metadaten einer Datei oder eines Ordners Download the New People Bible.
GetFiles($dropbox_path=”, $recursive=false)  Listet Dateien in einem Verzeichnis auf. Ist $recursive = true, werden Unterverzeichnisse rekursiv gelistet 산타나. Da jedes Verzeichnis eine neue Anfrage erfordert, kann das einige Zeit daueren!
DownloadFile($dropbox_file, $dest_path=”, $revision=-1)  Lädt eine Datei aus der Dropbox auf den Webserver certificate form. $dest_path gibt an, wo die Datei gespeichert wird (Zeilverzeichnis muss existieren). Mit $revision kann die Revision der Datei angegeben werden.
UploadFile($src_file, $dropbox_path=”)  Lädt eine Datei vom Webserver in die Dropbox Naver Calendar pc. Beachte, dass nur Dateien bis zu einer Größe von 150MB hochgeladen werden können!
GetLink($dropbox_file, $preview=true)  Gibt einen Link zu einer Dropbox-Datei zurück, mit dem jeder die Datei herunterladen kann windows xp iso 한글 다운로드. $preview gibt an, ob der Link auf eine Vorschauseite geht, anstatt direkt auf die Datei.
Delta($cursor)  Retrieves file changes. See delta
Copy($from_path, $to_path)  Copies a file or folder to a new location.
CreateFolder($path)  Creates a folder.
Delete($path)  Deletes a file or folder.
Move($from_path, $to_path)  Moves a file or folder to a new location.

Weitere Funktionen befinden sich in Entwicklung!

Authentifizierung

Die Dropbox API verwendet OAuth zur authentifizierung. Beim ersten Zugriff auf die Dropbox sendet der Dropbox server ein Request-Token. Der Benutzer wird zu einer Dropbox-Seite umgeleitet, wo er den Zugriff bestätigt. Anschließend wird mit dem gespeicherten Request-Token ein Access-Token ermittelt und gespeichert. Mit diesem lassen sich dann alle weiteren API-Anfragen authentifizieren.

DropPHP
DropPHP
master.zip.html
Version: 1.4
12 KiB
16055 Downloads
Details
Rating: 4.0/5. From 24 votes.
Please wait...
Voting is currently disabled, data maintenance in progress.

Verwandte Artikel

Kommentare

  • Ben sagt:

    Did anybody else notice that size (regardless of the doc: https://www.dropbox.com/developers/core/docs#thumbnails) always returns „s“ (max 64px).

    Code here:

    public function GetThumbnail($dropbox_file, $size = ‚m‘, $format = ‚png‘, $echo = false)
    { if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
    $url = $this->cleanUrl(self::API_CONTENT_URL.“thumbnails/$this->rootPath/$dropbox_file“);
    $content = http_build_query(array(‚format‘ => $format, ’size‘ => $size),“,’&‘);
    $context = $this->createRequestContext($url, „GET“, $content);

    if($this->useCurl) {
    curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($context, CURLOPT_RETURNTRANSFER, true);
    }

    $thumb = $this->useCurl ? self::execCurlAndClose($context) : file_get_contents($url, NULL, $context);

    if($echo) {
    header(‚Content-type: image/‘.$format);
    echo $thumb;
    unset($thumb);
    return;
    }

    return $thumb;
    }

  • nabil sagt:

    Hi, i used the library all good like 3 weeks ago and now everytime i want to download a file say:

    Fatal error: Uncaught exception ‘DropboxException’ with message ‘Download size mismatch!’

  • Fabi sagt:

    Hi nabil & Terrence,

    update to latest version 1.6, this fixes the issue.

  • Stefan sagt:

    Don’t know if DropBox changed it, but the upload did not work for me. Then I noticed in the core API docs that for /files_put the path parameter cannot be a folder, it must contain the filename.

    So when I changed the following line in the DropBoxClient

    $url = $this->cleanUrl(self::API_CONTENT_URL.“/files_put/$this->rootPath/$dropbox_path“).“?$query“;

    to

    $url = $this->cleanUrl(self::API_CONTENT_URL.“/files_put/$this->rootPath/$dropbox_path“).“/“.basename($src_file).“?$query“;

    it started working again. Took me a while to notice because I use this to back up my websites onto a DropBox account (dump database, zip all files, upload zip to DropBox), and the last CRON job that executes the backup-procedure returned an error.

    BTW, you say this works without cURL, but there’s still a lot of pointers to cUrl (which I removed: using libraries adds a level of abstraction that makes debugging these kinds of errors very difficult – I never use libraries if I can avoid it).

    • Fabi sagt:

      Hi Stefam,
      this is not a bug, $dropbox_path passed to the UploadFile function must be the full file path, NOT a path to the directory!

      The client work without cURL, on initializiation it checks for cURL beeing installed and falls back to PHP wrappers if it could not find it.
      You should always use libraries for performance reasons, cURL is faster than PHP HTTPS wrappers. The trick is to fall back to built in PHP functions if dependencies are not available.

      Regards
      Fabian

  • Anthony sagt:

    Hi Fabi,

    I have downloaded version 1.6 above but the error is still there:
    „Fatal error: Uncaught exception ‚DropboxException‘ with message ‚Download size mismatch! (header: vs actual:54‘ in“
    The script downloads the temp file then upload to S3.

    I also noticed that getting the files from an app folder includes the Getting Started.pdf file together with the files in the App folder. Using GetMetadata(). Not using delta because I’m not synching the files just getting the metadata to be listed on the database.

    Kind regards,
    Anthony

    • Fabi sagt:

      Hi Anthony,

      please try this version: https://fabi.me/download/DropboxClient.zip
      It gives more debug data if download fails.

      • Anthony sagt:

        Thanks Fabi. I will try this out.

      • Anthony sagt:

        Hi Fabi,

        This is what I got from the updated DropboxClient file that you gave.

        Thanks and regards,
        Anthony

        • Anthony sagt:

          Fatal error: Uncaught exception ‚DropboxException‘ with message ‚Could not retrieve meta data from header data: Array ( [0] => HTTP/1.1 403 Forbidden [1] => Server: nginx [2] => Date: Sun, 06 Oct 2013 10:14:28 GMT [3] => Content-Type: application/json [4] => Transfer-Encoding: chunked [5] => Connection: keep-alive [6] =>

        • Fabi sagt:

          Can you post the DownloadFile call including the parameters you are passing?

          • Anthony sagt:

            Hi Fabi,

            Here is my call:
            $GLOBALS[‚dropbox‘]->DownloadFile(‚/testfolder/bt-m2-timing.mp4′, dirname(__FILE__).’/media/‘.$values[1].’/‘.$filename);

            I only have 2 parameters. The dropbox file and the destinatio path.

            Thanks

          • Anthony sagt:

            Hi Fabi,

            I had a wrong App access details from before but after I have updated it to the right ones. I git this error on download function with the same parameters as above.

            Fatal error: Uncaught exception ‚DropboxException‘ with message ‚Could not retrieve meta data from header data: Array ( [0] => HTTP/1.1 400 Bad Request [1] => Server: nginx [2] => Date: Wed, 09 Oct 2013 09:17:33 GMT [3] => Content-Type: application/json [4] => Transfer-Encoding: chunked [5] => Connection: keep-alive [6] => ) ‚

            Thanks,
            Anthony

          • Anthony sagt:

            Hi Fabi,

            Digging more into the DropboxClient. The $response_headers variable gets:
            array(7) {
            [0]=>
            string(24) „HTTP/1.1 400 Bad Request“
            [1]=>
            string(13) „Server: nginx“
            [2]=>
            string(35) „Date: Wed, 09 Oct 2013 10:57:45 GMT“
            [3]=>
            string(30) „Content-Type: application/json“
            [4]=>
            string(26) „Transfer-Encoding: chunked“
            [5]=>
            string(22) „Connection: keep-alive“
            [6]=>
            string(0) „“
            }

            $context has „Resource id #10“

            $url is „https://api-content.dropbox.com/1/files/dropbox/testfolder/media-flow.jpg“

          • Anthony sagt:

            Here is my download file call:
            DownloadFile($dropbox_file=’/testfolder/mediamasher-flow.jpg‘, $dest_path=’/home/mediamas/public_html/testcalls/mediamasher_uploader_engine/media/2/mediamasher-flow.jpg‘)

          • Anthony sagt:

            Hi Fabi,

            I have another findings. The file actually downloaded but it can’t be opened. Tried an MP4 and a JPG file. Both have errors when opening on my machine.

            regards,
            Anthony

          • Fabi sagt:

            Anthony, have you tried SetUseCUrl(true/false) ?

          • Anthony sagt:

            Hi Fabi,

            Thank you for your support and creating DropPHP.
            I got the problem solved just now.

            The previous developer was calling the DropboxClient like this:
            $dropbox = new DropboxClient(array(
            ‚app_key‘ => DROPBOX_CONSUMER_KEY,
            ‚app_secret‘ => DROPBOX_CONSUMER_SECRET,
            ‚app_full_access‘ => true
            ),’en‘);

            That is why he’s getting Getting Started.pdf also from the Dropbox root.

            I changed ‚app_full_access’=>true to false but the issues above arose.

            I saw this code in DropboxClient:
            $this->rootPath = empty($app_params[‚app_full_access‘]) ? „sandbox“ : „dropbox“;

            and I changed it to:

            $this->rootPath = ($app_params[‚app_full_access‘] ? „dropbox“ : „sandbox“);

            It solved the 400 Error for me.
            I think empty($app_params[‚app_full_access‘]) defaults to dropbox and not to sandbox if the parameter is false, true, or if you pass any string or integer to it.

            Best regards,
            Anthony

  • FOXRULE sagt:

    Hi Fabi,

    I am finding following exception. Please guide me to run sample.php properly…
    Warning: file_put_contents(tokens/wgRUT5FVLUn8GHX0.token) [function.file-put-contents]: failed to open stream: No such file or directory in D:\PHP\application\dropbox\DropPHP-master\sample.php on line 106

    Could not store token! Make sure that the directory `tokens` exists and is writable!

  • zoe sagt:

    Hi I came across your client class file for dropbox php api. I am trying to use but I am unable to get meta information for all files of logged in user. Following is the output I receive:

    Files:
    Array
    (
    [0] => abc.html
    [1] => B1.docx
    [2] => Getting Started.pdf
    [3] => test_download_abc.html
    [4] => test_download_Getting Started.pdf
    [5] => xyz.html
    )

    Meta data of /abc.html:
    stdClass Object
    (
    [revision] => 4
    [rev] => 4131fc57f
    [thumb_exists] =>
    [bytes] => 361
    [modified] => Thu, 26 Sep 2013 04:55:26 +0000
    [client_mtime] => Thu, 26 Sep 2013 04:55:26 +0000
    [path] => /abc.html
    [is_dir] =>
    [icon] => page_white_code
    [root] => dropbox
    [mime_type] => text/html
    [size] => 361 bytes
    )

    this is the response obtained kindly tell me why other files in array are not considered for meta information

  • Awesome things here. I am very happy to peer your
    post. Thanks so much and I am taking a look forward to touch you.
    Will you kindly drop me a mail?

  • Moin,

    ich hab‘ da mal ´ne kurze Frage:
    Ist es möglich, Dateien aus einem Ordner in meiner Dropbox automatisch auf den Server zu laden?

    Wäre echt praktisch für mark2 (Flat-File Based Blogging-System an dem ich arbeite)..

    Gruß
    Flo

  • Jums sagt:

    Hi, I’ve installed and configured your script but when I try to upload a picture I keep getting this error:

    stdClass Object
    (
    [error] => Access token does not belong to this app.
    )

    done!

    Any ideas?

    Thanks!

    • Jums sagt:

      Already found what was causing this error.
      If you, like me, are testing with various dropbox accounts and getting this odd error, delete the access.token under the token folder.

      The script was using an access.token from another instance.

      Hope it helps.

      J

  • Glenn sagt:

    Hi Fabi,

    Firstly what an excellent script, great work!

    I am having issues with the length of time it takes to upload, i am trying to upload a file in the size of circa 400MB and its taking about 10 hours to complete, can you let me know if there is any settings i could tweak in order to get this going quicker?

    The server is using curl and when checked is returning 1 for function_exists(‚curl_init‘) so i assume its running via curl.

    The server is hosted on a big pipe so bandwidth speed should not be an issue?

    Thanks in advance for any ideas.

    Glenn

  • hi fabi, i am trying to create a „drop-zone“ to my dropbox account within a .php application. can you send me an email so i can explain further?

  • Hiren Raiyani sagt:

    Warning: file_put_contents(tokens/X0ae9FGYhdikFe39.token) [function.file-put-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\DropPHP\sample.php on line 106

    Could not store token! Make sure that the directory `tokens` exists and is writable!

  • ilovepie sagt:

    I want to do a web app, where users will put the credentials and I upload the data to their dropbox account. I see that I need to create an app with my account and I get a key, But where in the library I put the credentials of the user so upload files to different accounts?

    Thank you

  • […] have found a script I am trying to work with to make this possible. It is one made by Fabi to download and upload files […]

  • […] have found a script I am trying to work with to make this possible. It is one made by Fabi to download and upload files […]

  • Michael sagt:

    Hi Fabi,

    good Job, thank you.
    Can you tell me, how i can get the process of a file during the download?

    Thanks Michael

  • John Doe sagt:

    i want to ask few questions bro

    1) how we can increase image thumbanil size ?
    2) how we can limit the search record query ?
    3) why you upload 1st image again with concatinate string „test_download_“ and download it, and can how we can change the download image path ?

  • John Doe sagt:

    if i call app_key and app_secret for every user within a loop than how can i manage tokens for each user in tokens folder ?

  • Jimmy sagt:

    Hi,

    first of all thanks for the great script. i have a question!

    i want to download ALL files from my app_folder into a specific folder on my local / online-folder. can you please help me out?

    many thanks

  • Nikhil sagt:

    I was using ur API and build a web app. But when i try to delete one image from my dropbox, the api is throwing error:

    Fatal error: Uncaught exception ‚DropboxException‘ with message ‚Path ‚/fcb2.jpg“‚ not found‘ in C:\xampp\htdocs\project4\DropboxClient.php:597 Stack trace: #0 C:\xampp\htdocs\project4\DropboxClient.php(617): DropboxClient::checkForError(Object(stdClass)) #1 C:\xampp\htdocs\project4\DropboxClient.php(450): DropboxClient->apiCall(‚fileops/delete‘, ‚POST‘, Array) #2 C:\xampp\htdocs\project4\album.php(93): DropboxClient->Delete(‚/FCB2.jpg“‚) #3 {main} thrown in C:\xampp\htdocs\project4\DropboxClient.php on line 597

    I am calling the function as :
    if(isset($_POST[„delete“])){
    $path = substr($_GET[„id“], 1);
    $meta = $dropbox->Delete($path);
    //print_r($meta);
    }

    where im passing the path as ‚id‘ in the query string of the url.

    Kindly provide any sort of assistance.

  • Shamim sagt:

    I get a key, But where in the library I put the credentials of the user so upload files to different accounts? Thank you

  • Pete nice sagt:

    Dropbox V1 API endooints stop working on September 20 – any plans to update DropPHP to support the new API?

  • Anto Nishanth sagt:

    There are few issues with DropboxClient.php

    1. in function copy()

    Instead of return $this->apiCall( „fileops/copy“, array(

    it should be

    return $this->apiCall( „2/files/copy_v2“, array(

    2. In the same function ‚root‘ should not be one of parameter.

    I am only using copy function and come across these issues.

    Hope this may help some one.

    Appreciate your effort.

  • Jason Silver sagt:

    Hey Anto, is this the only issue with this api client as far as you know?

1 2 3 4

Schreibe einen Kommentar zu yz972 Antworten abbrechen

Deine E-Mail-Adresse wird nicht veröffentlicht.