0

can someone fix my code

this for my Route

Route::post('/ViewFile/{nama_file}', 'HSEController@getDownloadFile')->name('DownloadFile');

this for my View

<a href="{{ route('DownloadFile', $temuan->file) }}" target="_blank">File Lamp</a>

and this for my controller

public function ViewFile($nama_file)
{

  $file= public_path("/files/".$nama_file);
  $headers = [
        'Content-Type' => 'application/pdf',
        'Content-Disposition' => 'inline; '.$nama_file,
     ];

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

}

I used that code and the result is file always downloading, I want to change to open in my browser,

Ihsan
  • 35
  • 10

2 Answers2

1

Try this with the Content Disposition as inline.

return response()->file($file_path, [
  'Content-Disposition' => 'inline; filename="'. $file_path .'"'
]);
Saurabh
  • 2,655
  • 1
  • 20
  • 47
0

Try this:

public function ViewFile($nama_file)
{

  $file= public_path("/files/".$nama_file);
  $headers = [
        'Content-Type' => 'application/pdf',
        'Content-Disposition' => 'inline; '.$nama_file,
     ];

  return response()->streamDownload(function () {
    //do something here
     }, $file, $headers);

}
Elisha Senoo
  • 3,489
  • 2
  • 22
  • 29