2016-11-11 46 views
0

如何在下面卷曲的PHP代码修复如何FIC卷曲代码在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' 
+2

这并未除了您尝试使用命令行curl将PHP文件上传到Dropbox之外,似乎与PHP没有任何关系。 – Chris

+2

你会得到什么样的输出,它与你的期望有什么不同? –

回答

3

您是通过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/>');