PHP cURL komut satırı cURL dönüştürmek

4 Cevap php

Bu nedenle bazı yardım ihtiyacı duyuyorum ben önce herhangi kıvrılmasını yapmadım. Ben örneklerden bu işe çalıştım ama kafamın etrafında alınamıyor!

Ben başarılı bir API üzerinden bir wiki için bir dosya koyar bir linux (ubuntu) komut satırı çalıştırabilirsiniz bir curl komutu var.

Ben inşa ediyorum bir PHP komut dosyası bu kıvırmak komutu birleştirmek gerekir.

Bir PHP komut dosyası çalışır böylece nasıl ben bu curl komutu çevirebilir?

curl -b cookie.txt -X PUT \
     --data-binary "@test.png" \
     -H "Content-Type: image/png" \    
     "http://hostname/@api/deki/pages/=TestPage/files/=test.png" \
     -0

cookie.txt kimlik doğrulaması içerir ama bu sadece benim tarafımdan idare edilecek gibi komut açık metin bu koyarak bir sorun yok.

@ Test.png gibi $ dosya gibi bir değişken olmalıdır

http://hostname/@api/deki/pages/=TestPage/files/= gibi $ PAGEURL gibi bir değişken olmalıdır

Herhangi bir yardım için teşekkür ederiz.

4 Cevap

Bir başlangıç ​​noktası:

<?php

$pageurl = "http://hostname/@api/deki/pages/=TestPage/files/=";
$filename = "test.png";

$theurl = $pageurl . $filename;

curl_init($theurl);
curl_setopt($ch, CURLOPT_COOKIE, ...); // -b
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // -X
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: image/png']); // -H
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // -0

...
?>

Ayrıca bakınız: http://www.php.net/manual/en/function.curl-setopt.php

Bir başlangıç ​​noktası olarak MYYN cevabını kullanma, ve this page PHP cURL kullanarak POST veri göndermek için nasıl bir referans olarak, burada (ben şu anda çok benzer bir şey üzerinde çalışıyorum) benim öneri:

<?php

$pageurl = "http://hostname/@api/deki/pages/=TestPage/files/=";
$filename = "test.png";

$theurl = $pageurl.$filename;

$ch = curl_init($theurl);
curl_setopt($ch, CURLOPT_COOKIE, ...); // -b
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // -X
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: image/png']); // -H
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // -0

$post = array("$filename"=>"@$filename");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
$response = curl_exec($ch);
?>

Eğer arzu muhtemelen curl_setopt_array kullanımı ile birçok curl_setopts optimize edebilirsiniz () arayın.

Bu deneyin:

$cmd='curl -b cookie.txt -X PUT \
     --data-binary "@test.png" \
     -H "Content-Type: image/png" \    
     "http://hostname/@api/deki/pages/=TestPage/files/=test.png" \
     -0';
exec($cmd,$result);

- libcurl seçeneği ben PHP çevirmek oldukça kolay olması gerektiğini düşünüyorum, bir C programını yapar olsa bile, bu amaçla ilave edildi