-
Notifications
You must be signed in to change notification settings - Fork 0
/
lh-image.php
executable file
·55 lines (45 loc) · 1.44 KB
/
lh-image.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
<?php
class LH_Image
{
public function __construct($url = '') {
$this->setUrl($url);
}
public function setUrl($url) {
$this->url = $url;
}
public function exists()
{
$curl = curl_init($this->url);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'images.legiaodosherois/1.1');
curl_exec($curl);
if (200 != curl_getinfo($curl, CURLINFO_HTTP_CODE)) {
return false;
}
return true;
}
function grab()
{
$curl = curl_init($this->url);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'images.legiaodosherois/1.1');
$raw = curl_exec($curl);
if (false === $raw) {
return ['status' => 'error', 'reason' => 'internal_error'];
}
if (200 != curl_getinfo($curl, CURLINFO_HTTP_CODE)) {
return ['status' => 'error', 'reason' => 'not_found'];
}
curl_close($curl);
list($header, $body) = explode("\r\n\r\n", $raw, 2);
return $body;
}
}
function startsWith($haystack, $needle)
{
return $needle === '' || strrpos($haystack, $needle, -strlen($haystack)) !== false;
}