public function download($url, $toPath, $filename)
{
$basepath = dirname($toPath . '/' . $filename);
$basename = basename($filename);
// create this directory if it doesn't exist
if (!is_dir($basepath)) {
mkdir($basepath, 0755, true);
}
// use curl to download
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
// save the $data into this file
return file_put_contents($basepath . '/' . $basename, $data);
}