繁体   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