【发布时间】:2016-10-25 01:08:00
【问题描述】:
尝试制作匿名上传图片到 imgur 的脚本。运行时只是空白页。我需要发布带有标题和描述的图像(以 base 64 字符串格式)。对不起我的英语和代码。
<?
header ("Content-type: image/png");
$im = ImageCreate (200, 100);
$couleur_fond = ImageColorAllocate ($im, 255, 0, 0);
$client_id="d9514d92012b55a";
$pvars = base64_encode($im);
$timeout = 30;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id . ', title: title, description: description'));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
$out = curl_exec($curl);
curl_close ($curl);
$pms = json_decode($out,true);
$url=$pms['data']['link'];
?>
【问题讨论】:
-
您的代码似乎来自this blog post。您的代码似乎缺少某些内容,并且您的
client_id无效。我只是使用该博客文章中的代码和有效的client_id设置它,它工作正常。