Skip to content

Instantly share code, notes, and snippets.

@j67678
Last active August 29, 2015 14:16
Show Gist options
  • Save j67678/ac3ec37e95e99e30320c to your computer and use it in GitHub Desktop.
Save j67678/ac3ec37e95e99e30320c to your computer and use it in GitHub Desktop.
anti anti-link
name: cnbeta1
version: 1
handle:
- rewrite: if ( path ~ "^(.*)\.png$" ) goto "img.php?url=$1.png"
- rewrite: if ( path ~ "^(.*)\.gif$" ) goto "img.php?url=$1.gif"
- rewrite: if ( path ~ "^(.*)\.jpg$" ) goto "img.php?url=$1.jpg"
- rewrite: if ( path ~ "^(.*)\.jpeg$" ) goto "img.php?url=$1.jpeg"
<?php
$domain = 'img';
$url = 'http://static.cnbetacdn.com' . $_GET['url'];
$ext = pathinfo($url, PATHINFO_EXTENSION);
$filename = md5($url).'.'.$ext;
switch($ext) {
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpeg"; break;
default:
}
$s = new SaeStorage();
if ($s->fileExists($domain, $filename)) {
$img = $s->read($domain, $filename);
header('Content-type: ' . $ctype);
echo $img;
} else {
$f = new SaeFetchurl();
$content = $f->fetch($url);
if($f->errno() != 0) die($f->errmsg());
$s->write($domain, $filename, $content);
header('Content-type: ' . $ctype);
echo $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment