Skip to content

Instantly share code, notes, and snippets.

@tribulant
Created September 23, 2014 14:08
Show Gist options
  • Save tribulant/502d44a2a84e6c0614cd to your computer and use it in GitHub Desktop.
Save tribulant/502d44a2a84e6c0614cd to your computer and use it in GitHub Desktop.
//if the file doesn't exist, we'll try to copy it.
if (!file_exists($imagepath)) {
//Get the file
if ($content = file_get_contents($m[1])) {
if (!empty($content)) {
//Store in the filesystem.
$fp = fopen($imagepath, "w");
fwrite($fp, $content);
fclose($fp);
}
} else {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $m[1]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
$content = $output;
$fp = fopen($imagepath, "w");
fwrite($fp, $content);
fclose($fp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment