Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

php - How to display preview of uploaded pdf in laravel

I need to display pdf in the HTML page in laravel. I already upload the pdf from the form

protected function create(array $data){

  $request = request();

  $profileImage = $request->file('RESUMES');
  $profileImageSaveAsName = time().'.'. $profileImage->getClientOriginalExtension();
   
  $upload_path = 'Cvs';
  $profile_image_url = $upload_path . $profileImageSaveAsName;
  $success = $profileImage->move($upload_path, $profileImageSaveAsName);
  

  return User::create([
    'name' => $data['name'],
    'email' => $data['email'],
    'mobile' => $data['mobile'],
    'password' => Hash::make($data['password']),
    'RESUMES' => $profile_image_url,
       
  ]);
  //dd($user);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In your blade file you can embed the PDF file like so

<embed src="{{ asset('path-to-uploaded-file') }}" width="600" height="500" alt="pdf" />

If you want to display the PDF file in the browser you can add a button that redirects to

return response()->file($pathToFile);

return response()->file($pathToFile, $headers);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...