1

Well, I've uploaded an app to Heroku, and I've discovered that I can't upload files to it. Then I started to use Dropbox as storage option, and I've done a few tests, of send and retrieve link, and all worked fine.

Now, the problem is to use the uploadFile() method on DropboxAdapter. He accepts an resource as the file, and I did'nt work well. I've done a few tests, and still no way. Here is what I am doing, if anyone could me point a solution, or a direction to this problem, please. :)

Here is my actual code for the update user (Update the user image, and get the link to the file).

        $input = $_FILES['picture'];
        $inputName = $input['name'];
        $image = imagecreatefromstring(file_get_contents($_FILES['picture']['tmp_name']));

        Storage::disk('dropbox')->putStream('/avatars/' . $inputName, $image);

        // $data = Storage::disk('dropbox')->getLink('/avatars/' . $inputName);


        return dd($image);

In some tests, using fopen() into a file on the disk, and doing the same process, I've noticed this:

This is when I've used fopen() on a file stored on the public folder

https://i.stack.imgur.com/fc3vH.png

And this, when i've die(var_dump()) the $image that I've tried to create. (Which is a suggestion from this two links: PHP temporary file upload not valid Image resource, Dropbox uploading within script.

https://i.stack.imgur.com/7z4vx.png

Any Idea?

Community
  • 1
  • 1
pLpB
  • 23
  • 5
  • Did you try a simple fopen on the uploaded file? $image = fopen($_FILES['picture']['tmp_name']); – ChristianM Mar 07 '15 at 22:37
  • @ChristianM Man, If I could, I would kiss you! It works. I really didn't think about that. Please, post you comment as a answer so I can close this question. Thanks! – pLpB Mar 08 '15 at 00:09

1 Answers1

1

Try a simple fopen on the uploaded file:

$image = fopen($_FILES['picture']['tmp_name'], 'r');

https://www.php.net/manual/en/function.fopen.php

You don't need an image stream but just a filestream, which fopen provides.

ChristianM
  • 1,793
  • 12
  • 23