public function post_add_pdf() { $rules = Config::get('rules.add_pdf'); $validation = Validator::make(Input::all(), $rules); if ($validation->passes()) { $pdf = Input::file('pdf'); if (is_file($pdf['tmp_name']) and $pdf['error'] === UPLOAD_ERR_OK) { if (Pdfs::add(Input::all())) { return Redirect::to('add_pdf')->with('success', TRUE); } else { return Event::first('500', 'The PDF could not be added due to a system error. We apologize for any inconvenience.'); } } Session::flash('failed', TRUE); } return Redirect::to('add_pdf')->with_input()->with_errors($validation); }
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'); }