prestashop-1.6
2015-07-03 2 views 0 likes 
0

Это просто, но для меня это не просто. Я использую PHP 5.6.Prestashop API загрузить изображение ошибки PHP 5.6

Это работает:

<form method="post" action="http://[email protected]/api/images/products/88" enctype="multipart/form-data" > 
<input type='file' name='image' /> 
<button type="submit" >send</button> 
</form> 

Но это не так:

$id_product = 88; 
$cfile = curl_file_create('bigimage.jpg','image/jpeg','bigimage'); 

$data = array('image' => $cfile); 

$header = array('Content-Type: multipart/form-data'); 
$url = PS_SHOP_PATH . "api/images/products/$id_product"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_VERBOSE, true); 
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); 
curl_setopt($ch, CURLOPT_USERPWD, PS_WS_AUTH_KEY.':'); 
//curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.realpath('bigimage.jpg').";type=jpeg")); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

if(!$result = curl_exec($ch)) throw new Exception('curl_exec generate an error.'); 
curl_close($ch); 

Может кто-нибудь мне помочь? Может быть, это может быть ошибка безопасности? В журнале иногда отображается только ошибка 500.

ответ

3

Для меня я использую:

// envois de la nouvelle image 
    $url = PS_SHOP_PATH. "/api/images/products/".$product->id; 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_VERBOSE, true); 
    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); 
    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_mime)); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $result = curl_exec($ch); 
    curl_close($ch);  

Спасибо за размещение кода:

curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); 

Без него моя загрузка с ошибкой 500.

Thnaks снова!

Смежные вопросы