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,

13
  • Try it like this: <a href="{{ route('DownloadFile', $temuan->file) }}" target="_blank">File Lamp</a> Now it'll give you a option to download and print both in new window!! Commented May 22, 2018 at 5:19
  • Nope sir, still not working @HirenGohel Commented May 22, 2018 at 5:20
  • Also make this changes in your controller code: pastebin.com/QG2UDfTw Commented May 22, 2018 at 5:31
  • not work too @HirenGohel Commented May 22, 2018 at 5:37
  • This is working for me! Please refer this answer also: stackoverflow.com/questions/25938294/… Commented May 22, 2018 at 5:41

2 Answers 2

1

Try this with the Content Disposition as inline.

return response()->file($file_path, [
  'Content-Disposition' => 'inline; filename="'. $file_path .'"'
]);
Sign up to request clarification or add additional context in comments.

1 Comment

With the use of above code, if the PDF still being downloaded?
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);

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.