【问题标题】:Upload image on imgur with php用php在imgur上上传图片
【发布时间】: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'];


?>

【问题讨论】:

标签: php curl imgur


【解决方案1】:

如果您最终尝试打印 url,则应删除 header ("Content-type: image/png");

解释header ("Content-type: image/png"); 告诉浏览器在内容为纯文本或 html 时将其作为图像处理...


您还应该使用完整的php标签&lt;?php而不是短标签&lt;?

说明:有些服务器不解释以短php标签开头的php代码,而是将代码作为纯文本发送到浏览器。

【讨论】:

    猜你喜欢
    • 2014-04-28
    • 2014-05-09
    • 2015-01-12
    • 2018-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-20
    • 1970-01-01
    相关资源
    最近更新 更多