Reputation: 101
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?
Upvotes: 1
Views: 1332
Reputation: 36
Take a look at Flysystem. I'm using it with Laravel but I believe it also works as a standalone.
http://flysystem.thephpleague.com/
Upvotes: 1
Reputation: 94642
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".....`
^^^^^^^^^^^
Upvotes: 1