-2

I am using the below code. but still it's downloading the files instead of viewing.

public function viewFiles(StoreBusinessDevelopment $request, $file, $id)
{
    $businessDevelopment = BusinessDevelopment::select('created_by', 'rfp_id')
                                                ->where('id', '=', $id)
                                                ->get();

    $mimeType = File::mimeType(public_path('/uploads/'.$businessDevelopment[0]['created_by'].'/'.$businessDevelopment[0]['rfp_id'].'/'.$file));

    return response()->file(public_path('/uploads/'.$businessDevelopment[0]['created_by'].'/'.$businessDevelopment[0]['rfp_id'].'/'.$file),[
        'Content-Type' => $mimeType
    ]);
}
JON
  • 965
  • 2
  • 10
  • 28
Kiran Kumar P
  • 113
  • 2
  • 8

2 Answers2

0

You can just convert files to PDF format and then return it to browser.

Dmitriy Buteiko
  • 624
  • 1
  • 6
  • 14
0

Browser unable to read .doc|xls|xlsx files. But you can view / rander it by using some tricks.

Example 1

First upload the file like i say .doc|xls|xlsx and make it as array of data. By using php -> laravel that have a module/repo for excel file read and parse it as array. After make it as array and print this array as html table and browser must rander it.

For more info : Laravel Excel

Rashedul Islam Sagor
  • 1,943
  • 14
  • 20