1

I have written code for file uploading and it is working fine on one server but not on local machine. Following is code:

<?php

ini_set("display_errors",1);

$api_url = 'https://content.dropboxapi.com/2/files/upload'; //dropbox api url

$token = 'fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; 

$headers = array('Authorization: Bearer ' . $token,
    'Content-Type: application/octet-stream',
    'Dropbox-API-Arg: ' .
    json_encode(
            array(
                "path" => '/' . basename('image/1st.jpg'),
                "mode" => "add",
                "autorename" => true,
                "mute" => false
            )
    ),
    'Content-Type: application/octet-stream'
);

$ch = curl_init($api_url);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);

$path = 'images/1st.jpg';

$fp = fopen($path, 'rb');
$filesize = filesize($path);

curl_setopt($ch, CURLOPT_POSTFIELDS, fread($fp, $filesize));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1); // debug

$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo "<pre>response === "; print_r($response); echo "</pre>";
echo "<pre>http_code === "; print_r($http_code); echo "</pre>";


?>

When i run this code on local, i got following output:

response === 
http_code === 0

On test server, it produce following output:

{"name": "1st.jpg", "path_lower": "/1st.jpg", "path_display": "/1st.jpg", "id": "id:UDbOKdE2bKXXXXXXECg", "client_modified": "2017-10-10T10:05:11Z", "server_modified": "2017-10-10T10:05:11Z", "rev": "4075316e33a", "size": 143578, "content_hash": "f30041XXXXXXXXXXX35ee3cXXXXXXe649afe8d"}
200

what can be possible reason for this issue?

2
  • What does curl_error($ch); shows ? Commented Oct 11, 2017 at 12:27
  • SSL certificate problem: unable to get local issuer certificate Commented Oct 11, 2017 at 12:30

2 Answers 2

2

Try to disable SSL veryfy host: curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

Or more correct way is:

Download a file with the updated list of certificates from https://curl.haxx.se/ca/cacert.pem

Move the downloaded cacert.pem file to some safe location in your system

Update your php.ini file and configure the path to that file:

; Linux and macOS systems
curl.cainfo = "/path/to/cacert.pem"

; Windows systems
curl.cainfo = "C:\path\to\cacert.pem"
Sign up to request clarification or add additional context in comments.

1 Comment

i think this is not an answer so should be posted as comment instead of question.
-1

Following steps resolved issue for me:

1) Download the latest cacert.pem from https://curl.haxx.se/ca/cacert.pem

2) Add the following line to php.ini

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.