Download Image from external url

This tutorial explains how to download a file from the external link and save that image in a folder.Please refer the download file function which do the downloading and save that file.

Please refer the tutorial which explains how to set the downloaded file as the main and additional images in magento . Before downloading it checks whether the folder contain that image if not it starts downloading the file to folder.

     /*   This function download the file from the external url and save that in a folder */
        
        // download File
        
        
function downloadFile($url, $path)
{
    $newfname = $path;
    $file = fopen ($url, 'rb');
    if ($file) {
        $newf = fopen ($newfname, 'wb');
        if ($newf) {
            while(!feof($file)) {
                fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
            }
        }
    }
    if ($file) {
        fclose($file);
    }
    if ($newf) {
        fclose($newf);
    }
}

Share this Tutorial