phpdropbox-php

PHP upload to dropbox, file not being recognized


I'm sure I'm missing something here but I'm not sure what. I am able to upload files to dropbox via a library. However the file is uploaded but the file is not recognized (viewable). Here are the details.

Library being used: Spatie\Dropbox\

My form to receive the upload(html):

<form action="http://127.0.0.1:8000/dropboxFileUpload" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="uploadvideo" id="file">
    <input type="submit" value="Upload Image" name="submit">
</form>

My controller (actually in Laravel but I think it doesn't matter)

 public function dropboxFileUpload(Request $request)
  {
      $client = new Client(env('DROPBOX_TOKEN'));

      $name=$_FILES['uploadvideo']['name'];
      $type=$_FILES['uploadvideo']['type'];
      $cname=str_replace(" ","_",$name);
      $tmp_name=$_FILES['uploadvideo']['tmp_name'];
      $targetPath = 'justshoot/' . $cname;

      $upload = $client->upload($targetPath, $tmp_name);

      dd($tmp_name);
  }

in Dropbox the file gets posted to the directory and name as specified. In example if I upload 'myimage.jpg'. It appears in dropbox under justshoot/myimage.jpg.

The error says "Jpg is a recognizeable format but something went wrong", any idea what I'm doing wrong?

EDIT: I can confirm the file is good, I've also tried multi files, save thing.


Solution

  • The problem with my code above was that I wasn't actually getting the file content. I added this: $fileContent = file_get_contents($_FILES['uploadvideo']['tmp_name']);

    Then did my call with the fileContent;

    $upload = $client->upload($targetPath, $fileContent);