使用php在imgur上上传图像 [英] Upload image on imgur with php

查看:112
本文介绍了使用php在imgur上上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图制作脚本,将脚本匿名上传到imgur上。运行时只是空白页。我需要发布带有标题和描述的图像(基本64字符串格式)。抱歉我的英语和代码。

Trying to make script which uploading image on imgur anonymously. Just blank page when I run it. I need to post image(in base 64 string format) with title and description. Sorry for my english and code.

<?
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'];


?>


推荐答案

如果您尝试在最后,您应该删除标题( Content-type:image / png);

If you're trying to print the url in the end, you should remove the header ("Content-type: image/png");.

说明 header( Content-type:image / png); 告诉浏览器将内容显示为纯文本或html ...

Explanation: header ("Content-type: image/png"); tells the browser to behave with the content as image while it is a plain text or html...

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

You should also use full php tag <?php instead of the short one <?

解释:有些服务器不会解释以短php标记开头的php代码,而是以纯文本形式将代码发送到浏览器。

Explanation: Some servers do not interpret php code starting with short php tag and send the code to browser as plain text.

这篇关于使用php在imgur上上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆