我打算使用其 api 匿名上传图像到 imgur,我在匿名上传类别中注册了我的应用程序并获得了客户端 ID 和客户端密码,如何使用 php 将图像上传到 imgur 并检索图像的直接 url?任何人都可以建议任何示例的链接吗?这是我试图做的,但我收到错误“致命错误:超过 30 秒的最大执行时间”
<?php
$client_id = :client_id; //put your api key here
$filename = "images/q401x74ua3402.jpg";
$handle = fopen($filename, "r");
$data = fread($handle, filesize($filename));
//$data is file data
$pvars = array('image' => base64_encode($data), 'key' => $client_id);
$timeout = 30;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/upload.json');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
$xml = curl_exec($curl);
$xmlsimple = new SimpleXMLElement($xml);
echo '<img height="180" src="';
echo $xmlsimple->links->original;
echo '">';
curl_close ($curl);
?>