2016-03-29 12 views
1

biz it information kullanımı vardır ve kod:imgur ticaret - resim nasıl albüme yüklenir? imgur.com üzerinde albümde yükleme resim için

$image = file_get_contents($_FILES['upload']['tmp_name']); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://imgur-apiv3.p.mashape.com/3/image'); 
curl_setopt($ch, CURLOPT_POST, TRUE); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id)); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Mashape-Key: ' . $xmash)); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); 
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => base64_encode($image))); 
curl_setopt($ch, CURLOPT_POSTFIELDS, array('album' => $album_id)); 
curl_setopt($ch, CURLOPT_POSTFIELDS, array('type' => 'base64')); 
curl_setopt($ch, CURLOPT_POSTFIELDS, array('name' => 'test_name')); 
curl_setopt($ch, CURLOPT_POSTFIELDS, array('title' => 'test title')); 
curl_setopt($ch, CURLOPT_POSTFIELDS, array('description' => 'blablabla')); 
$result= curl_exec($ch); 
var_dump($result); 
curl_close($ch); 

ama sonuçta biz hatayı Invalid image type almak vardır.

Söyle bana neden hata alıp albümdeki görüntüyü gönderiyoruz?

P.S .: Biz test ticaretinin sorumluluğundayız.

curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => $baseContent)); 

:

cevap

0

imajınızı sağlayın Sonra sadece isteğinize geçmesine ..

$baseContent = ""; 

if (isset($_FILES['upload']['tmp_name'])) { 
     $imgbinary = fread(fopen($_FILES['upload']['tmp_name'], "r"), filesize($_FILES['upload']['tmp_name'])); 
     $baseContent = 'data:image/png;base64,' . base64_encode($imgbinary); 
    } 

Bu base64 için $baseContent Var ayarlayacaktır .. ilk base64 göndermeden önce doğru olarak yapılandırılmıştır Doğru biçimlendirmiyor gibi görünüyor. Bunu tamamen test edemedim ama doğru tabana sahip olmandan emin olmalı64.

İlgili konular