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
16399 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
16399 Downloads
Details
Rating: 4.0/5. From 24 votes.
Please wait...
Voting is currently disabled, data maintenance in progress.

Verwandte Artikel

Kommentare

  • Jason Silver sagt:

    I just discovered your solution this evening, and it seems very simple. I am getting the same problem as Dekel however.

    Warning: file_get_contents(http://api-content.dropbox.com/1/files_put/sandbox/hst-number.txt?overwrite=1&locale=en) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden
    in /home3/crookedb/public_html/servicebuilder/dropbox/DropboxClient.php on line 214

    Slight difference in that I’m getting a file_get_contents error where Dekel is geting a file_put_contents error.

    Any ideas to fix this?

    • Fabi sagt:

      I have just uploaded an Update:
      = 1.3 =
      * cURL is used if installed, this fixes some issues with PHP HTTP wrapper using cURL
      * Fixed minor bugs

      Please try this version, it might fix your issue.

  • Uli sagt:

    Hi Fabi, is there a reason that UploadFile() is not working? When using it (and removing the die() and the disbling of curl for it), I first got a
    HTTP/1.1 411 Length Required

    I solved this by adding
    curl_setopt($context, CURLOPT_UPLOAD,1);
    in UploadFile()

    Then it actually uploads something to Dropbox (my file is 30 MB, so you can see the upload time) but then the return from Dropbox is
    < HTTP/1.1 100 Continue
    Invalid or missing signature

    (Output using CURLOPT_VERBOSE => true)

    The HTTP header looks ok and contains the Authorization line:

    > PUT /1/files_put/dropbox/home/Apps/MyApp/home/user/file.pdf HTTP/1.1
    Host: api-content.dropbox.com
    Accept: */*
    Authorization: OAuth oauth_token=“gi1esduigefm5l2″, oauth_nonce=“805abd546b2b583a99664b27f679172d“, oauth_timestamp=“1357252187″, oauth_consumer_key=“btuk5prfdeja589″, oauth_signature_method=“HMAC-SHA1″, oauth_version=“1.0″, oauth_signature=“iPxe%2F%2F5u7CyoHqaNvmuBjd6NYFA%3D“
    Content-Length: 26691888
    Expect: 100-continue

    Do you know what could be the reason?

    Thanks in advance
    Uli

    • Fabi sagt:

      Hello Uli,

      I thinks its because the API Parameters must be appended as a query string to the URL when doing a PUT request. Maybe cURL screws it up.
      It might help to compare the requests made by PHP wrapper and cURL using a network sniffer like WinScp.

      Regards
      Fabian

  • paul sagt:

    Thanks for this – I have dropbox enabled my web gallery that already a 1-1 „clone“ of the dropbox folder structure, so with this, I could easily add some delete functionality that makes sense!

    With kind regards,
    Paul

  • Stone sagt:

    Upload file method doesn’t work.

  • Fabio Parri sagt:

    Would that be possible to use your class to sideload a file hosted on a remote server direclty to a dropbox account?

    For instance, I am browsing the web on my phone and I’d like to sideload to Dropbox some big files so I can find them directly on my box when I get home.

  • Ryan sagt:

    Hi I previously asked about downloading dropbox files around november and I didn’t get a reply. I’m still curios as to how I can download a file from my dropbox app folder to a destination folder. I have tried different ways and its still not working. I’m not good with php so I need all the help I can get please or a sort of example to guide me.

  • Carlos sagt:

    Hi there,

    Im unable to download a previous version of a file.
    Is this happening to someone?

    Regards.

  • Zoltan sagt:

    Any ideea why i’m getting this error when i try uploading files?
    [error] => Upload failed. Content-Type must not be empty and not one of (‚application/x-www-form-urlencoded‘, ‚multipart/form-data‘)

    I checked the Content-Type and it’s set to:
    Content-Type: application/octet-stream

  • Adrian sagt:

    Hi I am trying to follow your code to create a folder but the code in step 2 and 3 are garbled. Can you kindly reproduce it?

    Thanks

  • PeterJK sagt:

    I am very very happy with your dropbox classes!

    Although I ran into one problem: I am trying to download en entire folder with images (50 of them). But when downloading, it stops at image 25 or 23 every time. How is that? How can I solve this?

    Is there a caching risk or something somewhere in the code?

    Thanks for your help.

  • Ron Knee sagt:

    Great – thank you very much!
    It worked more or less ‚out of the box‘, although to upload to a Dropbox subdirectory I made the following changes to DropBoxClient:
    a) inserted an extra variable into the second position here: public function UploadFile($src_file, $fold, $dropbox_path=“, $overwrite=true, $parent_rev=null)
    and
    b) inserted this variable here: if(empty($dropbox_path)) $dropbox_path = $fold.basename($src_file);

    So $dropbox_path is always null.

    In Sample, you call the UploadFile function using 2 parameters – the second being the destination folder (put a slash at the end).

    Ron

  • james sagt:

    Hi,

    the API-Calls (especially curl_exec($ch)) are very slow (at least in Vienna…)
    it takes around 0.8 – 1.1 seconds for each call. (it’s for sure not a problem of DropPHP, but of dropbox)
    Do you experience the same?

    you can measure this by extending the function apiCall:

    $start = microtime(true); // new line

    $json = $this->useCurl ? self::execCurlAndClose($context) : file_get_contents($url, false, $context); // existing line

    echo „duration apiCall: „.(1000*$duration).“ ms“; // new line

    James

  • PeterJK sagt:

    @ james:

    Hi James,

    True. I experience the same. Even so much that much shared webhosting thinks it should stop my script halfway… 🙁

    Any solution to make this faster or to go around it?

    • james sagt:

      Hi PeterJK,
      I added some caching-functionality, that means I’m fetching only the list of files and save the information (json-ized) into a file in the tokens-directory. If there’ll be another request to the same list of files within the next 5 minutes, I’ll take the information from the cache.

      The list of files holds all necessary information to be able to display the files, but the link. That information ( GetLink ) I retrieve on demand, means, if someone tries to download a file the Link will be fetched and executed. I also cache that information. As the List of Files gives you information about the modification date of the file you can easily confirm wether the link you cached is still the right one or if it’s necessary to run „GetLink“ again to update the cache.

      Works excellent this way!

  • Neha sagt:

    Hi,
    This is such a nice article i spent out 5 hrs to work with dropbox but didn’t find something good which is workable but this article is awesome very easy to make it runnable. Can you provide me the way or code to download all the file or selected files from dropbox as i am not too expert in PHP code.

    Thanks & Regards
    Neha

  • Lauda sagt:

    Could someone please make a patch for the caching stuff? At the moment it is a bit slow, so caching system is a must…but sadly, I’m not that good to implement that. 🙁

  • Younes sagt:

    Thx u for the upload method.

    I want ask you about:

    => I want get the LAST picture put in a folder in the user dropbox.

    This is my email : sppop1@gmail.com

    Thx u

  • Prabhu sagt:

    Hi Friends,

    Thanks for sample code.

    I unable to change the thumbnail image size, Is it possible?

    Please advise and help me/

    Thanks
    prabhu

  • Hi! I got downloading file to server working. However, can anyone help me how I can get the file to download to the client computer; so for anyone who comes to my site would receive the file from Dropbox itself instead of going from dropbox to server to client?

    Thanks!

  • Vignesh sagt:

    Hi Fabian,
    Your Script Works and i want users to upload to my account and i am using Dropbox uploader by Jaka Jancar for uploading it . But i cant create folder and manipulate it using that script.
    And how can it be done using your scripts??.
    Regards,
    Vignesh Dhamodaran.

  • Anup sagt:

    Awesome. Also, i would love to get a script which resides in the web server and automatically back up all the files and databasees in the webserver periodically over dropbox. That would be great.

  • Ben sagt:

    I wasn’t able to perform an upload successfully yet, although i’m sure i’m just doing something foolish. Here’s the output of the uploadFile process, with some debug info turned on.

    SOURCE: /tmp/php5KwiYb
    DB PATH: /coffee_0001.jpg
    OVERWRITE?: false
    function_exists(‚curl_version‘): true
    URL:http://api-content.dropbox.com/1/files_put/dropbox/coffee_0001.jpg?overwrite=0&locale=en

    Warning: file_get_contents(http://api-content.dropbox.com/1/files_put/dropbox/coffee_0001.jpg?overwrite=0&locale=en): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
    in /var/www/dropboxfun/api/dropbox/DropboxClient.php on line 336

  • yz972 sagt:

    Hi,

    First of all many thanks for this great api !
    Still this weekend we have problem to use the api => „…HTTP/1.1 401 Unauthorized…“
    After 1 month of work fine& after a dropbox update, we got this problem.
    Did you have an idea on what going wrong ?

    Thks & best regards

  • yz972 sagt:

    It’s ok for me now, i just have to delete all tokens files to create a new one & everything is now work fine.
    Ben thks you to because, i also have the pb et your solution work perfectly !
    🙂

  • Juan Felipe sagt:

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

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

1 2 3 4

Schreibe einen Kommentar zu Ben Antworten abbrechen

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