Imgur.com API $Post title og description
Hej Eksperter.Nu har jeg til uendeligheder bikset med en API kode til imgur.com ..
Det er lykkedes mig at lave et upload af billedet uden nogen problemer, men i dettet uploade ønsker jeg også at have mulighed for at sætte en title og en description på billedet.
Jeg har søgt nettet tynd for et eksempel på hvordan den kode skal se ud men uden held.
Håber en af jer har tid til at vise mig hvordan koden skal se ud for det er muligt.
Her er min nuværende kode :
<!DOCTYPE html>
<html>
<head>
<title>Image Upload Using Imgur API</title>
</head>
<body>
<div id="content" style="margin-top:10px;height:100%;">
<center><h1>Image Upload Using Imgur API</h1></center>
<form action="index.php" enctype="multipart/form-data" method="POST">
Choose Image : <input name="img" size="35" type="file"/><br/>
Title: <input type="text" name="title" />
Description: <input type="text" name="Description" />
<input type="submit" name="submit" value="Upload"/>
</form>
<?
if(isset($_POST['submit'])){
$img=$_FILES['img'];
if($img['name']==''){
echo "<h2>An Image Please.</h2>";
}else{
$filename = $img['tmp_name'];
$client_id="xxx";//Your Client ID here
$handle = fopen($filename, "r");
$data = fread($handle, filesize($filename));
$pvars = array('image' => base64_encode($data));
$timeout = 30;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/m4PT1tr/{test}');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id));
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'];
if($url!=""){
echo "<h2>Uploaded Without Any Problem</h2>";
echo "<img src='$url'/><br>";
echo $pms['data']['link']. "<br>";
echo str_replace("http://","https://", "$url<br>"); // dette er https versionen.
echo $pms['data']['id']. "<br>";
echo $pms['data']['type']. "<br>";
}else{
echo "<h2>There's a Problem</h2>";
echo $pms['data']['error']['message'];
}
}
}
?>
</div>
<style>
input{
border:none;
padding:8px;
}
</style>
<!-- http://www.subinsb.com/2013/11/upload-images-with-imgur-api-in-php.html' -->
</body>
</html>