2016-11-11 87 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/>');