-
Notifications
You must be signed in to change notification settings - Fork 0
/
tumblr2.php
32 lines (30 loc) · 866 Bytes
/
tumblr2.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
<?php
/**
* tumblr2.php
*
* Recives tumblr post URL and return its photo
*
* @author ysidorito
* @copyright 2014 Rodolfo Pilas
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
* @link https://github.com/ysidorito/tumblr-photo-url
*/
function getImg($postUrl){
$url = explode("/", $postUrl);
$data = file_get_contents("htt"."p://".$url[2]."/mobile/post/".$url[4]);
preg_match_all('<a href="(.*?)">',$data,$matches,PREG_PATTERN_ORDER);
return $matches[1][0];
}
$imgUrl = getImg($_GET['u']);
$ext = strtolower(array_pop(explode('.',$imgUrl)));
$mime_types = array(
'png' => 'image/png',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'gif' => 'image/gif',
);
header("Content-type:".$mime_types[$ext]);
$photo = file_get_contents($imgUrl);
print_r($photo);
?>