Frage

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");
War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top