2016-06-22 119 views
1

试图使匿名上传imgur图片的脚本生效。我运行它时只是空白页面。我需要发布带有标题和说明的图像(以64位字符串格式)。对不起,我的英文和代码。使用php在imgur上上传图片

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


?> 
+0

相关:http://stackoverflow.com/questions/4372710/php-curl-https – AllInOne

+0

它看起来像你的代码来自[本博客文章](http://subinsb.com/uploading-images-using- imgur-API中的PHP)。你的代码似乎缺少一些东西,而你的'client_id'是无效的。我只是使用该博客文章中的代码和有效的'client_id'来设置它,它工作正常。 – APAD1

回答

0

如果你想在最后打印网址,你应该删除header ("Content-type: image/png");

说明header ("Content-type: image/png");告诉浏览器与内容的图像表现,同时它是一个纯文本或HTML ...


您还应该使用完整的PHP标签<?php,而不是缺一<?

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