Get image from external link, save it to temp directory and upload via PS webservice.
function SetCategoryImage($cat_id, $image_url) {
/* Prepare the image filename */
$imgURL = urldecode($image_url);
$image_name = (stristr($imgURL,'?',true))?stristr($imgURL,'?',true):$imgURL;
$pos = strrpos($image_name,'/');
$image_name = substr($image_name,$pos+1);
/* Check the directory. Create if not exist*/
if (!file_exists('/tmp/img/')) mkdir('/tmp/img/', 0777, true);
/* Copy image to local temp*/
$ch = curl_init($image_url);
$fp = fopen('/tmp/img/'.$image_name, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
/* Set the local image path*/
$image_path = '/tmp/img/'.$image_name;
/* Set the API URL for category*/
$url = PS_SHOP_PATH .'/api/images/categories/'.$cat_id;
/* Upload image using CURL */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, PS_WS_AUTH_KEY.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path.';type=image/jpeg'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
}