protected function downloadFile($url, $path, $filename)
{
if (!($fp = fopen($path . '/' . $filename, 'w+'))) {
throw new RuntimeException('Impossible to write to path: ' . $path);
}
// curl looks like shit but whatever
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}