Skip to content

Instantly share code, notes, and snippets.

@ganchiku
Created January 31, 2013 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ganchiku/4684675 to your computer and use it in GitHub Desktop.
Save ganchiku/4684675 to your computer and use it in GitHub Desktop.
<img src="{{ post.catchimage | get_remote_image | imagine_filter('large')}}" class="img-polaroid" style="width:260px;height:260px;" alt="{{ post.catchcaption }}" />
// ...
public function get_remote_image($url)
{
$tokens = explode(".", $url);
$extension = $tokens[sizeof($tokens) - 1];
$webdir = __DIR__ .'/../../../../../web';
if (!is_dir($webdir .'/media/proxy')) {
mkdir($webdir .'/media/proxy', 0777, true);
}
$name = md5($url);
$relativepath = '/media/proxy/' . $name . '.' . $extension;
$fullpath = $webdir . $relativepath;
$result = true;
if (!is_file($fullpath)) {
$result = file_put_contents($fullpath, file_get_contents($url));
}
if ($result) {
return $relativepath;
} else {
return '/images/noimage.jpg';
}
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment