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 the different options that I have used:
- $app=new DropboxApp($consumerKey,$consumerSecret,$accessToken);
$dropbox=new Dropbox($app);
// Check if file was uploaded
if (isset($_FILES["file"])) {
// File to Upload
$file = $_FILES['file'];
// File Path
$fileName = $file['name'];
$filePath = $file['tmp_name'];
try {
// Create Dropbox File from Path
$dropboxFile = new DropboxFile($filePath);
// Upload the file to Dropbox
$uploadedFile = $dropbox->upload($dropboxFile, "/" . $fileName, ['autorename' => true]);
// File Uploaded
echo $uploadedFile->getPathDisplay();
} catch (DropboxClientException $e) {
echo $e->getMessage();
}
}
2. This one creates the folder but does not save the file...
$inputData=Yii::$app->request->post();
$dropboxFile = new DropboxFile($filePath);
$folderName = $inputData['Model']['file];
$file = $dropbox->upload($dropboxFile, "/".$fileName, ['autorename' => true]);
$folderName = $inputData['Model']['file'];
$folder = $dropbox->createFolder($dropboxFile,"/".$folderName);
$path = 'https://www.dropbox.com/home/.../...' .$file->path_display;
$dropbox_path = array('dropbox_path'=>$path);
$inputData['Model']['dropbox_path'] = $path;
$model->load($inputData);
$model->save(false);
}
Any suggestion? Other code that I can implement to it?
Thanks in advance.