Code: Select all
define("PS_SHOP_PATH", 'http://midominio.com/');
define("PS_WS_AUTH_KEY", 'XXXXXXXXXXX' );
$img= _PS_TMP_IMG_DIR_ .$mifoto ;
$curl = curl_init();
curl_setopt($curl,CURLOPT_HEADER, true);
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl,CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_URL, PS_SHOP_PATH . '/api/images/products/' . $id_produc );
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, PS_WS_AUTH_KEY );
curl_setopt($curl, CURLOPT_POSTFIELDS, array('image' => '@'.$img) );
if( ! $result = curl_exec($curl))
{ echo $crlf .'Error : '.$idproduc.' '.$img.' -> '.curl_error($curl). $crlf; }
else { echo $result. '<br>. Image added: ' . $nomfoto . $crlf ; }
curl_close($curl);
Code: Select all
#include "hbcurl.ch"
Function main()
Local cApiUrl := "http://24h.vinaros.net/prestashop_16/api/"
Local cApiKey := 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
Local hWebService
Local cUrl
Local cImagen
curl_global_init()
hWebService := curl_easy_init()
If !empty(hWebService)
cUrl :=cApiUrl+'images/products/1'
cImagen:='C:\pruebas\imagen.jpg'
curl_easy_setopt(hWebService,HB_CURLOPT_HEADER, .T.)
curl_easy_setopt(hWebService,HB_CURLOPT_RETURNTRANSFER, .T.)
curl_easy_setopt(hWebService,HB_CURLINFO_HEADER_OUT, .T.)
curl_easy_setopt(hWebService,HB_CURLOPT_URL, cUrl )
curl_easy_setopt(hWebService,HB_CURLOPT_POST, .T.)
curl_easy_setopt(hWebService,HB_CURLOPT_HTTPAUTH, HB_CURLAUTH_BASIC)
curl_easy_setopt(hWebService,HB_CURLOPT_USERPWD, cApiKey)
curl_easy_setopt(hWebService,HB_CURLOPT_POSTFIELDS, {'image',cImagen})
curl_easy_setopt(hWebService, HB_CURLOPT_DL_BUFF_SETUP )
If curl_easy_perform (hWebService)<>0
msginfo ('error')
Else
memowrit ('resultado.xml',curl_easy_dl_buff_get( hWebService ))
Endif
Endif
curl_global_cleanup()
Return (nil)
Code: Select all
curl_setopt($curl, CURLOPT_POSTFIELDS, array('image' => '@'.$img) );
Code: Select all
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => new CurlFile($imagePath)));