簡體   English   中英

如何在PHP中FIC curl代碼

[英]How to fic curl code in php

如何在curl PHP中修復以下代碼

curl -X POST https://content.dropboxapi.com/2/files/upload \
  --header 'Authorization: Bearer Cf6jn41fHMAAAAAAAAAAgpH1o7IHHaUTWZNNdFSYVlcLb8K-fcnLXbEXnd3lK6Mv' \
  --header 'Content-Type: application/octet-stream' \
  --header 'Dropbox-API-Arg: {"path":"/my.html","mode":{".tag":"add"},"autorename":true}' \
  --data-binary @'upload.php'

您正在通過CURL通過POST執行二進制文件上傳 ,請嘗試以下操作:

$YourString = file_get_contents("upload.php");
$stream = fopen('php://memory','r+');
fwrite($stream, $YourString );
$dataLength = ftell($stream);
rewind($stream);

$curl = curl_init();
curl_setopt_array( $curl,
    array( CURLOPT_CUSTOMREQUEST => 'POST'
    , CURLOPT_URL => 'https://content.dropboxapi.com/2/files/upload'
    , CURLOPT_HTTPHEADER => array('Authorization: Bearer Cf6jn41fHMAAAAAAAAAAgpH1o7IHHaUTWZNNdFSYVlcLb8K-fcnLXbEXnd3lK6Mv','Content-Type: application/octet-stream','Dropbox-API-Arg: {"path":"/my.html","mode":{".tag":"add"},"autorename":true}')
    , CURLOPT_RETURNTRANSFER => 1                     // means output will be a return value from curl_exec() instead of simply echoed
    , CURLOPT_TIMEOUT => 15                           // max seconds to wait
    , CURLOPT_FOLLOWLOCATION => 0                     // don't follow any Location headers, use only the CURLOPT_URL, this is for security
    , CURLOPT_FAILONERROR => 0                        // do not fail verbosely fi the http_code is an error, this is for security
    , CURLOPT_SSL_VERIFYPEER => 1                     // do verify the SSL of CURLOPT_URL, this is for security
    , CURLOPT_VERBOSE => 0                            // don't output verbosely to stderr, this is for security
    , CURLOPT_INFILE => $stream
    , CURLOPT_INFILESIZE => $dataLength
    , CURLOPT_UPLOAD => 1
    ) );

$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
echo($response.'<br/>');
echo($http_code.'<br/>');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM