forked from delete/imgur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgur.php
62 lines (55 loc) · 1.39 KB
/
imgur.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
*
* Script para Upload no imgur.com
*
* Esse script tem como função fazer o upload de uma imagem
* E para isso ele usar o site imgur.com como hospedagem
*
* @author Gildásio Júnior
* @link gildasio.net
*
**/
function upload($img){
$ch = curl_init();
$data = array(
'Filedata' => "@$img"
);
curl_setopt($ch,CURLOPT_URL,'http://imgur.com/upload');
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$up = curl_exec($ch);
curl_close($ch);
preg_match("/\"success\":(.*?),\"status\"/i",$up,$ok);
if($ok[1] === 'true'){
preg_match("/hashes\":\[\"(.*?)\"\],\"hash/i",$up,$link);
$link = 'Link of image: http://imgur.com/'.$link[1];
return $link;
}
elseif($ok[1] === 'false'){
$erro = 'An error occurred, please try again later.';
$erro = $erro."\n";
$erro = $erro.'Or report in gildasio.net';
return $erro;
}
else{
$erro = 'An error occurred, please try again later.';
$erro = $erro."\n";
$erro = $erro.'Or report in gildasio.net';
return $erro;
}
}
if((count($argv) != 2) || !(is_file($argv[1])) || !(file_exists($argv[1]))){
echo "\nScript by Gildasio Junior";
echo "\nSee more in gildasio.net";
echo "\n\n";
echo "Use: php $argv[0] [an imagem location]";
echo "\n\n";
exit;
}
echo "\nScript by Gildasio Junior";
echo "\nSee more in gildasio.net";
echo "\n\n";
echo upload($argv[1])."\n\n";
?>