|
用PHP做imgur的中转:
- <?php
- $imgur = $_SERVER['QUERY_STRING'] ;
- if(!preg_match('/^([a-z0-9]{5})\.(png|jpg|gif)$/i', $imgur, $m))
- die('Not a valid imgur image');
- $fname='./cache/'.$m[1].'.'.$m[2];
- if(file_exists($fname)){
- header('Content-type: image');
- die(file_get_contents($fname));
- }
- $con = stream_context_create(array('http'=>array('timeout'=>15)));
- $image = @file_get_contents('http://i.imgur.com/'.$imgur,0,$con);
- if(!$image) die('Cannot retrieve imgur file');
- file_put_contents($fname, $image);
- header('Content-type: image');
- echo $image;
Copy the Code reddit.com/r/reddit.com/comments/f2jh4/i_made … r_mirror_noncaching/ |
|