massel's avatar

View uploaded file in new window

I am trying to view a file in new window instead of download, but when I click it opens in the same window as my app so I have to click the browser back button to go back to the app can anyone be of help this is the code below. its a PDF file

use Illuminate\Support\Facades\Storage; use Illuminate\Http\Response;

$pathToFile = "C:/xampp/htdocs/project/storage/files/file.pdf"; if(Storage::exists($pathToFile)) { $fileContent = Storage::get($pathToFile);;

           $contentType = Storage::mimeType($pathToFile);

         
           return (new Response($fileContent, 200))
           ->header('Content-Type', $contentType)
           ->header('Content-Disposition', 'inline');
        }
0 likes
4 replies
gych's avatar

Can you share the code of your view where you call the route that returns the file.

gych's avatar

@massel What actions are happening?

When the user uploads the file is it directly returned of does the user click on a link to view the file?

massel's avatar

@gych Thanks I got it solved its target="_blank"

1 like

Please or to participate in this conversation.