PHP ActiveX Dropbox: Dropbox Move a File to another Folder

Back to Index

Move a file or folder to a different location in the user's Dropbox. If the source path is a folder all its contents will be moved.

Documentation: https://www.dropbox.com/developers/documentation/http/documentation#files-move

CURL Command

curl -X POST https://api.dropboxapi.com/2/files/move_v2 \
    --header "Authorization: Bearer DROPBOX-ACCESS-TOKEN" \
    --header "Content-Type: application/json" \
    --data "{\"from_path\": \"/Homework/math/ghost_emoji.txt\",\"to_path\": \"/Halloween/emojis/ghost.txt\",\"allow_shared_folder\": false,\"autorename\": false,\"allow_ownership_transfer\": false}"

PHP ActiveX Example

<?php

$rest = new COM("Chilkat_9_5_0.Rest");

//  URL: https://api.dropboxapi.com/2/files/move_v2
$bTls = 1;
$port = 443;
$bAutoReconnect = 1;
$success = $rest->Connect('api.dropboxapi.com',$port,$bTls,$bAutoReconnect);
if ($success != 1) {
    print 'ConnectFailReason: ' . $rest->ConnectFailReason . "\n";
    print $rest->LastErrorText . "\n";
    exit;
}

//  See the Online Tool for Generating JSON Creation Code
$json = new COM("Chilkat_9_5_0.JsonObject");
$json->UpdateString('from_path','/Homework/math/ghost_emoji.txt');
$json->UpdateString('to_path','/Halloween/emojis/ghost.txt');
$json->UpdateBool('allow_shared_folder',0);
$json->UpdateBool('autorename',0);
$json->UpdateBool('allow_ownership_transfer',0);

$rest->AddHeader('Authorization','Bearer DROPBOX-ACCESS-TOKEN');
$rest->AddHeader('Content-Type','application/json');

$sbRequestBody = new COM("Chilkat_9_5_0.StringBuilder");
$json->EmitSb($sbRequestBody);
$sbResponseBody = new COM("Chilkat_9_5_0.StringBuilder");
$success = $rest->FullRequestSb('POST','/2/files/move_v2',$sbRequestBody,$sbResponseBody);
if ($success != 1) {
    print $rest->LastErrorText . "\n";
    exit;
}

$respStatusCode = $rest->ResponseStatusCode;
if ($respStatusCode >= 400) {
    print 'Response Status Code = ' . $respStatusCode . "\n";
    print 'Response Header:' . "\n";
    print $rest->ResponseHeader . "\n";
    print 'Response Body:' . "\n";
    print $sbResponseBody->getAsString() . "\n";
    exit;
}

$jsonResponse = new COM("Chilkat_9_5_0.JsonObject");
$jsonResponse->LoadSb($sbResponseBody);

//  See the Online Tool for Generating JSON Parse Code

$from_path = $jsonResponse->stringOf('from_path');
$to_path = $jsonResponse->stringOf('to_path');
$allow_shared_folder = $jsonResponse->BoolOf('allow_shared_folder');
$autorename = $jsonResponse->BoolOf('autorename');
$allow_ownership_transfer = $jsonResponse->BoolOf('allow_ownership_transfer');

?>

Sample JSON Response Body

{
  "from_path": "/Homework/math/ghost_emoji.txt",
  "to_path": "/Halloween/emojis/ghost.txt",
  "allow_shared_folder": false,
  "autorename": false,
  "allow_ownership_transfer": false
}