Start 2025 on time and up to date. Seamlessly integrate your calendars into Dropbox with these simple steps.
Forum Discussion
rasbox
5 years agoNew member | Level 2
Downloading a file from a shared folder PHP CURL
I have a business account and we have files in a shared folder. I currently can list of files within folder and this is an example of response I get
#items: array:500 [▼ 0 => array:12 [▼ ".tag" => "file" "name" => "file.mp4" "parent_shared_folder_id" => "8693457712" "id" => "id:6_UMBoPQ5zAAAAAAAAAqcQ" "client_modified" => "2020-04-26T00:17:02Z" "server_modified" => "2020-11-19T14:20:38Z" "rev" => "015b4766e9661ac00000002062ba330" "size" => 1952676954 "sharing_info" => array:3 [ …3] "is_downloadable" => true "has_explicit_shared_members" => false "content_hash" => "4e9217a7937cfae02cdb41d4baf9b1126f555729ee2a38a0b82d9d27ac320bae" ]
Now, everytime I try to download the file from dropbox to a local path I get folder not found.
I'm using function below:
function dbx_get_file($token, $in_filepath, $out_filepath) { $out_fp = fopen($out_filepath, 'w+'); if ($out_fp === FALSE) { echo "fopen error; can't open $out_filepath\n"; return (NULL); } $url = 'https://content.dropboxapi.com/2/files/download'; $header_array = array( 'Authorization: Bearer ' . $token, 'Content-Type:', 'Dropbox-API-Arg: {"path":"' . $in_filepath . '"}', 'Dropbox-Api-Select-User: dbmid:ffffffffff-fhfdjkfhkjfdshkj' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array); curl_setopt($ch, CURLOPT_FILE, $out_fp); $metadata = null; curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($ch, $header) use (&$metadata) { $prefix = 'dropbox-api-result:'; if (strtolower(substr($header, 0, strlen($prefix))) === $prefix) { $metadata = json_decode(substr($header, strlen($prefix)), true); } return strlen($header); } ); $output = curl_exec($ch); if ($output === FALSE) { echo "curl error: " . curl_error($ch); } curl_close($ch); fclose($out_fp); return($metadata); }
Now issue is path.
Assuming my folder name is "My Company", what would be the path? I've tried below patterns
- foldername/filename
- parent_shared_folder_id/filename
- parent_shared_folder_id/file id
- /
- null
And I keep getting path not found. Has anyone having the same issue?
- Greg-DBDropbox Staff
It looks like the file isn't being found because the API call doesn't have the correct root. That is, it seems like this file is in your team space, but by default API calls operate in the team member folder, not the team space. You can configure calls to access the team space though, by setting the 'Dropbox-API-Path-Root' header. Please read the Team Files Guide for information on using this functionality.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,928 PostsLatest Activity: 14 hours ago
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!