Reputation: 5034
I'm trying to translate the following cURL command to PHP.
curl -k https://api.box.com/2.0/files/content -H "Authorization: Bearer 8tuuIMsrf3ShyODVdw" -F [email protected] -F folder_id=0
Here is my attempt:
$url = 'https://api.box.com/2.0/folders/content';
$params['filename'] = '@txt.txt';
$params['folder_id'] = '0';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$this->access_token, "Content-Type: multipart/form"));
$data = curl_exec($ch);
curl_close($ch);
It's not working however. Can anyone help me understand why what I'm doing is wrong and what I can do to modify my code? Thanks!!
Upvotes: 2
Views: 1009
Reputation: 157967
curl -k
means insecure. Add the following line:
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
Translated from the german manual (Note that the english version is missing this information):
If CURLOPT_SSL_VERIFYPEER has been deactivated, the option CURLOPT_SSL_VERIFYHOST has to be disabled as well.
The rest of your code should work fine.
Upvotes: 2
Reputation: 69937
Try getting rid of the header "Content-Type: multipart/form"
from your CURLOPT_HTTPHEADER
option as cURL will take care of this for you based on your post data.
Since you are uploading a file, the content-type will automatically be set to multipart/form-data
which is actually the correct content type, not multipart/form
.
Upvotes: 2