Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
jary_capstone
8 years agoHelpful | Level 5
Uploading files from a file server to DropBox
I've been adding some code to upload a file from my server to a specific folder in Dropbox but nothing successful. I'm using Yii2 advanced framework. (Php, javascript and html code in it). These are...
- 8 years ago
Based on this code, it looks like you've switched to using this other "Dropbox Uploader" library:
https://github.com/jakajancar/DropboxUploader
We do not recommend using this. From the its own readme:
"Its development was started before Dropbox released their API, and to work, it scrapes their website. So you can and probably should use their API now as it is much more stable."
I recommend using a third party library that actually uses the API, like you were before, or calling the API directly.
jary_capstone
8 years agoHelpful | Level 5
You actually got to the point... the method did not succesfully run.
I change the code to a different one and now it's running but it's not saving in the desire folder: using DropboxUploader
<?php
if ($_POST) {
require 'DropboxUploader.php';
try {
// Rename uploaded file to reflect original name
if ($_FILES['file']['error'] !== UPLOAD_ERR_OK)
throw new Exception('File was not successfully uploaded from your computer.');
$tmpDir = uniqid('/tmp/DropboxUploader-');
if (!mkdir($tmpDir))
throw new Exception('Cannot create temporary directory!');
if ($_FILES['file']['name'] === "")
throw new Exception('File name not supplied by the browser.');
$tmpFile = $tmpDir.'/'.str_replace("/\0", '_', $_FILES['file']['name']);
if (!move_uploaded_file($_FILES['file']['tmp_name'], $tmpFile))
throw new Exception('Cannot rename uploaded file!');
// Enter your Dropbox account credentials here
$uploader = new DropboxUploader('email', 'password');
$uploader->upload($tmpFile, $_POST['dest']);
echo '<span style="color: green;font-weight:bold;margin-left:393px;">File successfully uploaded to my Dropbox!</span>';
} catch(Exception $e) {
echo '<span style="color: red;font-weight:bold;margin-left:393px;">Error: ' . htmlspecialchars($e->getMessage()) . '</span>';
}
// Clean up
if (isset($tmpFile) && file_exists($tmpFile))
unlink($tmpFile);
if (isset($tmpDir) && file_exists($tmpDir))
rmdir($tmpDir);
}
?>
Greg-DB
Dropbox Community Moderator
8 years agoBased on this code, it looks like you've switched to using this other "Dropbox Uploader" library:
https://github.com/jakajancar/DropboxUploader
We do not recommend using this. From the its own readme:
"Its development was started before Dropbox released their API, and to work, it scrapes their website. So you can and probably should use their API now as it is much more stable."
I recommend using a third party library that actually uses the API, like you were before, or calling the API directly.
- jary_capstone8 years agoHelpful | Level 5
I'll try my best. If it start to give me errors or problems for upload a file then I will recurr here to the forum and ask about it.
Thanks
About Discuss Dropbox Developer & API
Make connections with other developers
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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, Facebook or Instagram.
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!