I am trying to download a file from a remote website using cronjob and save it on my hosting. For this purpose I am using the following function but unable to achieve the desired results. When i run the function no file is downloaded.
function save_image($inPath,$outDir, $outPath) {
$in = fopen($inPath, "rb");
if (!is_dir($outDir)) { mkdir($outDir); }
$out = fopen($outPath, "wb");
while ($chunk = fread($in,8192)) {
fwrite($out, $chunk, 8192);
}
fclose($in);
fclose($out);
}
save_image($dataurl,"data/","data/$filename");