Mam to vyriesene. Ak chcete poslat post request s typom multipart/form-data s obrazkom v poli files:
Kód:
$url = "cesta_k_serveru";
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "meno:heslo");
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
"uploadedFile"=>"@/cesta/k/suboru/delfin.jpg;type=image/jpeg",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($ch);
curl_close ($ch);
Ak post request s typom multipart/form-data s obrazkom v poli post ako binarne data (nie som si isty, ci je toto spravne):
Kód:
$localFile = 'delfin.jpg';
$ch = curl_init();
$fp = fopen($localFile, 'r');
$url = "cesta_k_serveru";
curl_setopt($ch, CURLOPT_USERPWD, "meno:heslo");
curl_setopt($ch, CURLOPT_URL, $url);
$data = 'POST tu_cesta_na_serveri HTTP/1.0
Host: nieco.com
Content-type: multipart/form-data, boundary=AaB03x
Content-Length: '.filesize($localFile).'
--AaB03x
content-disposition: form-data; name="delfin.jpg"; filename="delfin.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
'.file_get_contents('delfin.jpg').'
--AaB03x--';
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
Ak put request:
Kód:
$url = "cesta_k_serveru";
$localFile = 'delfin.jpg';
$fp = fopen($localFile, 'r');
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, "meno:heslo");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 86400);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localFile));
$result = curl_exec($ch);
curl_close ($ch);