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");
有帮助吗?

解决方案

You need to download the file and save it.fopen can be used only for opening the local file.if you want to download and save the remove file,you can use php curl api.

you refer the following link for downloading and saving the remote file.

Download Remote File to Server with PHP

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top