1

I am so close. I am trying to create a form that will upload a file to my Dropbox, and I can get it to work using a file on the server with the code here:

$path = 'render.png';
$fp = fopen($path, 'rb');
ch = curl_init('https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);curl_close($ch);
echo $response;

I was sure this would work, but nope.....

$fp = fopen($_FILES['file'], 'rb');

Anyone have a quick fix for this?

3
  • Did you authorise? Commented Mar 7, 2017 at 3:01
  • Yes I have other code with the headers. The code at the top works, it will upload the 'render.png' file. The problem is getting the file from the form $_FILES['file'] to work. I get an empty file on the server. Commented Mar 7, 2017 at 3:14
  • What is the name of the input for the file in your HTML Commented Mar 7, 2017 at 3:17

2 Answers 2

1

This is your problem

$fp = fopen($_FILES['file'], 'rb');

You will need to use the tmp_name field from $_FILES as that is the location of the temporary file that PHP places in the temp folder.

$fp = fopen($_FILES['fred']['tmp_name'], 'rb');

Where 'fred' is the value of the name attribute in

<input type="file" name="fred".....`
                   ^^^^^^^^^^^
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I knew I was missing something really simple.
1

Take a look at Flysystem. I'm using it with Laravel but I believe it also works as a standalone.

http://flysystem.thephpleague.com/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.