2014-08-29 188 views
1

發佈圖像目前,上傳本地文件夾中的圖像我使用捲曲和PHP,這裏是我的代碼:PHP捲曲從URL

$url = 'http://myprestashop.com/api/images/products/1'; 

$image_path = 'C:\\my_image.png'; 
$key = 'My web service key'; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_USERPWD, $key.':'); 
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path)); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$result = curl_exec($ch); 
curl_close($ch); 

我怎樣才能員額從URL(http://imageserver.com/image.jpeg)圖像,而不是本地文件夾( C:\ my_image.png)?可能嗎?

+0

我覺得你需要這樣。從prestashop.com得到迴應,當你顯示curl需要顯示你的圖像從其他服務器,如果我是正確的,那麼它可能 – 2014-08-29 05:03:11

回答

-1

只是改變你的圖像路徑,並嘗試這段代碼。

$url = 'http://myprestashop.com/api/images/products/1'; 

$data = array('key' => 'My web service key', 'image_path' => '@/home/user/test.png'); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$result = curl_exec($ch); 
curl_close($ch); 
+0

我需要從URL中獲取圖像,而不是像你的代碼 – torayeff 2014-08-29 07:17:44

+0

那麼你爲什麼不只是發佈圖像的網址並將其存儲在數據庫中。 – 2014-08-29 07:31:47

+0

這不是我需要的情況,我需要POST圖像到PrestaShop WebService它需要什麼,而不是URL – torayeff 2014-08-29 07:34:29