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);
}
/** * Fire events when you see this job has been * called back * * @param $output * @param $storagePath * @return void */ public function handle($output, $storagePath) { switch ($output['state']) { case 'finished': $filename = $output['label']; $fromUrl = $output['url']; $file = $this->FileDownloader->download($fromUrl, $storagePath, $filename); $this->Event->fire('devise.encoding.zencoder.finished', [$file, $output]); break; default: $this->Event->fire('devise.encoding.zencoder.error', [$output]); break; } }