php
  • api
  • dropbox-api
  • 2017-10-11 14 views 0 likes 
    0

    ファイルをアップロードするためのコードを記述しましたが、1台のサーバで正常に動作していますが、ローカルマシンでは正常に動作しています。 、それは出力テストサーバー上でカスタムPHPでV2を使用してDropboxにファイルをアップロード

    response === 
    http_code === 0 
    

    次生成します:

    <?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>"; 
    
    
    ?> 
    

    私はローカルでこのコードを実行すると、私は出力以下しまっ:以下のコードである

    {"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 
    

    ことができますかこの問題の理由は? curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

    以上の正しい方法は次のとおりです:ホストveryfy SSLを無効にする

    +0

    をphp.iniに以下の行を追加します。 );ショー? –

    +0

    SSL証明書の問題:ローカル発行者証明書を取得できません – RokiE

    答えて

    0

    1)https://curl.haxx.se/ca/cacert.pem

    2から最新のcacert.pemのダウンロード)curl_error($ CHを何

    0

    てみ

    https://curl.haxx.se/ca/cacert.pem

    からの証明書の更新リストを使用してファイルをダウンロードし、ダウンロードcacert.pemのファイルを移動しますあなたのシステムの安全な場所

    php.iniファイルを更新し、そのファイルへのパスを設定してください:

    私のための問題解決の手順に従い
    ; Linux and macOS systems 
    curl.cainfo = "/path/to/cacert.pem" 
    
    ; Windows systems 
    curl.cainfo = "C:\path\to\cacert.pem" 
    
    +0

    これは答えではないと思いますので、質問の代わりにコメントとして投稿する必要があります。 – RokiE

    関連する問題