- 
  Notifications
 
You must be signed in to change notification settings  - Fork 182
 
Working with files
Get the Metadata for a file or folder.
Example
$file = $dropbox->getMetadata("/hello-world.txt");
With options:
$file = $dropbox->getMetadata("/hello-world.txt", ["include_media_info" => true, "include_deleted" => true]);
Fetch file details:
//Id $file->getId(); //Name $file->getName(); //Size $file->getSize();
The getMetadata() method will return an instance of the FileMetadata model.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-get_metadata
Get the contents of a Folder.
Example
$listFolderContents = $dropbox->listFolder("/"); //Fetch Items $items = $listFolderContents->getItems(); //Fetch Cusrsor for listFolderContinue() $cursor = $listFolderContents->getCursor(); //If more items are available $hasMoreItems = $listFolderContents->hasMoreItems();
The listFolder() method will return an instance of the MetadataCollection model.
$listFolderContents = $dropbox->listFolder("/"); //Fetch Items (Returns an instance of ModelCollection) $items = $listFolderContents->getItems(); //All Items $items->all(); //First Item $items->first(); //Last Item $items->last();
Further calling the getItems() method of the MetadataCollection model, will return an instance of the ModelCollection model, which extends the awesome Collection class. See it's Available methods.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder
Paginate through all files and retrieve updates to the folder, using the cursor retrieved from listFolder or listFolderContinue.
Example
$listFolderContents = $dropbox->listFolder("/"); //Process listFolder Items ... //If more items are available if ($listFolderContents->hasMoreItems()) { //Fetch Cusrsor for listFolderContinue() $cursor = $listFolderContents->getCursor(); //Paginate through the remaining items $listFolderContinue = $dropbox->listFolderContinue($cursor); $remainingItems = $listFolderContinue->getItems(); }
The listFolderContinue() method will return an instance of the MetadataCollection model, same as the listFolder method.
Get a cursor for the folder's state.
Example
//Fetch the latest cursor $cursor = $dropbox-listFolderLatestCursor("/Public"); //Use this cursor to check if any files/folders where modified //post this cursor was obtained $modifiedItems = $dropbox->listFolderContinue($cursor)->getItems();
The listFolderLatestCursor() method will return a cursor.
Using this cursor with the listFolderContinue() method will return an instance of the MetadataCollection model, with the files/folders that have been modified since the cursor was obtained with listFolderLatestCursor method.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder-get_latest_cursor
Get Revisions of a File
Example
$revisions = $dropbox->listRevisions("/hello-world.txt", ["limit" => 3]); //All Revisions $revisions->all(); //First Revision $revisions->first(); //Last Revision $revisions->last();
The listRevisions() method will return an instance of the ModelCollection model, which extends the awesome Collection class. See it's Available methods.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-list_revisions
Search a folder for files/folders.
Example
$searchQuery = "hello world"; $searchResults = $dropbox->search("/", $searchQuery, ['start' => 0, 'max_results' => 5]); //Fetch Items $items = $searchResults->getItems(); //Fetch Cusrsor for calling search() with the `start` parameter/option for pagination $startCursor = $searchResults->getCursor(); //If more items are available if ($searchResults->hasMoreItems()) { //Pagination $moreSearchResults = $dropbox->search("/", $searchQuery, ['start' => $startCursor, 'max_results' => 5]); }
The search() method will return an instance of the SearchResults model, which extends the MetadataCollection model.
$searchQuery = "hello world"; $searchResults = $dropbox->search("/", $searchQuery, ['start' => 0, 'max_results' => 5]); //Fetch Items (Returns an instance of ModelCollection) $items = $searchResults->getItems(); //All Items $items->all(); //First Item (Returns an instance of SearchResult) $item = $items->first(); //Get the type of match, that was found for the result $item->getMatchType(); //Get the Metadata of the File or Folder $item->getMetadata();
Further calling the getItems() method of the SearchResults model, will return an instance of the ModelCollection model, where each item will be an instance of the SearchResult model.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-search
Create a folder at the given path
Example
$folder = $dropbox->createFolder("/My Folder"); //Name $folder->getName();
The createFolder() method will return an instance of the FolderMetadata model.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-create_folder
Delete a file or folder at the given path
Example
$deletedFolder = $dropbox->delete("/My Folder"); //Name $deletedFolder->getName();
The delete() method will return an instance of the DeletedMetadata model.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-delete
Restore a file to the specific version
Example
$revision = "rev:a1c10ce0dd78"; $restoredFile = $dropbox->restore("/Hello-World.txt", $rev); //Name $restoredFile->getName();
The restore() method will return an instance of either of the FileMetadata, FolderMetadata and DeletedMetadata models.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-restore
Move a file or folder to a different location
Example
$file = $dropbox->move("/Private/Hello-World.txt", "/Public/Hello-World.txt"); //Name $file->getName();
The move() method will return an instance of either of the FileMetadata, FolderMetadata and DeletedMetadata models.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-move
Copy a file or folder to a different location
Example
$file = $dropbox->copy("/Private/Hello-World.txt", "/Public/Hello-World.txt"); //Name $file->getName();
The copy() method will return an instance of either of the FileMetadata, FolderMetadata and DeletedMetadata models.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-copy
Get a copy reference to a file or folder. This reference string can be used to save that file or folder to another user's Dropbox by passing it to saveCopyReference().
Example
$copyReference = $dropbox->getCopyReference("/Hello-World.txt"); //Get Reference $copyReference->getReference();
The getCopyReference() method will return an instance of the CopyReference model.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-copy_reference-get
Save a copy reference returned by getCopyReference to the user's Dropbox.
Example
$copyReference = $dropbox->getCopyReference("/Hello-World.txt"); //Get Reference $reference = $copyReference->getReference(); //Save Copy Reference $file = $dropbox->saveCopyReference("/My-Hello-World.txt", $reference); //Name $file->getName();
The saveCopyReference() method will return an instance of either of the FileMetadata and FolderMetadata models.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-copy_reference-save
Get a temporary link to stream contents of a file.
Example
$temporaryLink = $dropbox->getTemporaryLink("/my-logo.png"); //Get File Metadata $file = $temporaryLink->getMetadata(); //Get Link $temporaryLink->getLink();
The getTemporaryLink() method will return an instance of the TemporaryLink model.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-get_temporary_link
Get a thumbnail for an image file.
Example
//Available sizes: 'thumb', 'small', 'medium', 'large', 'huge' $size = 'small'; //Default size //Available formats: 'jpeg', 'png' $format = 'jpeg'; //Default format $file = $dropbox->getThumbnail('/my-logo.jpg', $size, $format); //Get File Contents $contents = $file->getContents(); //Save File Contents to Disk file_put_contents(__DIR__ . "/my-logo.jpg", $contents); //Get File Metadata $file->getMetadata();
The getThumbnail() method will return an instance of the Thumbnail model.
For details & available options see: https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail