I'm building a small app for a client to backup critical files dropbox. This is happening simultaneously as certain are uploaded to the client's website. Specifically, the files are .jpg, and .png files.
The issue that I'm having is that the files are 'uploading', but the uploaded files are only about 860 bytes on DropBox. I've been banging my head against the wall for over 8 hours, and can't find anything but the most scant documentation about this functionality. Below is the code I'm using. The file path and file names come from the file upload, and I have verfied that the image is fully uploaded / moved before proceeding with uploading the file to DropBox.
<?php
$path = getcwd();
$file_location = $path.'/images/'.$filename;
clearstatcache(); // Clear file stats to ensure accurate info
$filesize = filesize($file_location);
// Conditional to make sure the complete file is there
if($filesize >= $_FILES["fichier"]["size"]){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.dropboxapi.com/2/files/save_url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"path\": \"/images//".$filename."\",\"url\": \"http://www.ClientsWebsiteUrl.com/images/".$filename."\"}");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$headers[] = "Content-Type: application/json";
//
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error '.curl_error($ch);
}else{
echo 'File Uploaded to DropBox';
}
curl_close ($ch);
}
?>
I'm hoping for any help I can get here, as I am out of ideas. Thanks everyone!