Why is the download of an excel file forced?

2

I am trying to show an excel file, but this one instead of showing what it does is download it at once.

Thus I try to show the file

public function ari(){

     $file = storage_path() . '\app\excel\formulario ORIGINAL ARI.xlsx';
     $headers = ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];

     return response()->file($file, $headers);
}

However if I deal with a file pdf I have no problem.

public function cardAval(){

    $file = storage_path() . '\app\pdf\carta-aval.pdf';
    $headers = ['Content-Type' => 'application/pdf'];

    return response()->file($file, $headers);

}

So the browser shows me the file and does not force the download as in the file excel , What am I wrong?

    
asked by Edwin Aquino 24.09.2018 в 18:41
source

1 answer

4

Actually you're not doing anything wrong, browsers can only view simple files such as txt, videos, audios, pdf and some other that I'm escaping. As far as I know, Excel files can not be displayed, for that you should have installed a plugin that allows you to view this type of files directly in the browser. But it would depend on the end user to install or not that plugin.

You could force that type of files to be displayed using the Google Drive viewer:

<a href="http://docs.google.com/viewer?url=http://www.comercial.usm.cl/wp-content/uploads/2015/10/vica.com_.mx_Promociones_assets_promocion2.pdf" title="Quotes" target="_blank">http://www.comercial.usm.cl/wp-content/uploads/2015/10/vica.com_.mx_Promociones_assets_promocion2.pdf</a>

<iframe src="http://docs.google.com/viewer?url=http://www.comercial.usm.cl/wp-content/uploads/2015/10/vica.com_.mx_Promociones_assets_promocion2.pdf&embedded=true" width="600" height="300" style="border: none;"></iframe>

Source: link

Greetings!

    
answered by 24.09.2018 / 18:57
source