'Image download - image cannot open issue

I tried to create some code so that a user can download an image in laravel without right clicking and using Save as... but after I created this code and download the image, trying to open the image says the image was damage.

        $file = urldecode($request->file);            
        $remoteURL = $base_url.$file;  
        //$fname = basename($remoteURL);  
        // echo $remoteURL;
        // exit; 
        // header('Content-type: image/*'); 
        header('Cache-Control: must-revalidate');
        header("Content-Type: application/octet-stream"); 
        header('Expires: 0');
        // header('Content-Disposition: attachment; filename='.basename($remoteURL));
        header('Content-Disposition: attachment; filename="'.basename($remoteURL).'"');
        // header('Content-Length: '. filesize($remoteURL));
        header('Pragma: public');
        flush();
        readfile($remoteURL);
        // file_get_contents($remoteURL);
        exit;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source