Example #1
0
 public function get_view_pdf($tmp_name)
 {
     if (preg_match('/\\w{40}/', $tmp_name)) {
         $file = path('storage') . "pdfs/{$tmp_name}";
         if (file_exists($file) && is_file($file)) {
             $pdf = Pdfs::where_tmp_name($tmp_name)->first();
             // View the PDF description for guest/expired users.
             if (Auth::guest() or User::is_expired()) {
                 return view('content.view_pdf')->with('pdf', $pdf);
             }
             // Add to 'Your Viewing History'.
             History::add_pdf($pdf->id);
             // Laravel will handle the headers.
             return Response::download($file, $pdf->file_name);
         }
     }
     return Response::error('404');
 }