Created
January 31, 2013 17:38
-
-
Save ganchiku/4684675 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img src="{{ post.catchimage | get_remote_image | imagine_filter('large')}}" class="img-polaroid" style="width:260px;height:260px;" alt="{{ post.catchcaption }}" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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