Laravel file downloaded from repository folder damaged

I tried to load a jpg / png image from the storage folder, after which it will be damaged. This is my controller

public function download($filename) {

    $headers = array(
        'Content-Type: image/png',
    );
    return response()->download(storage_path() . '/'.$filename, 'final.png', $headers);

}

after opening it looks like this: enter image description here

Even I used the core php script to load the fixed iam facing the same problem.

+4
source share
2 answers

I believe the Laravel framework can introduce spaces that can destroy the header () function.

Use ob_end_clean () before the first call to header () to remove extra spaces.

+4
source

add this method before doing this

ob_end_clean();
$headers = array(
    'Content-Type: image/png',
);
return response()->download(storage_path() . '/'.$filename, 'final.png', $headers);

! Enjoy

+2
source

Source: https://habr.com/ru/post/1653671/


All Articles