“Tampilkan file PDF di Laravel” Kode Jawaban

Cara menyimpan informasi tentang file PDF di proyek Laravel

$pdf = PDF::loadView('pdf.invoice', $data);

Storage::put('public/pdf/invoice.pdf', $pdf->output());

return $pdf->download('invoice.pdf');
Yawning Yak

Unggah file PDF Laravel

class FileController extends Controller
{
    // ...

    public function upload(Request $request)
    {
        $uniqueFileName = uniqid() . $request->get('upload_file')->getClientOriginalName() . '.' . $request->get('upload_file')->getClientOriginalExtension());

        $request->get('upload_file')->move(public_path('files') . $uniqueFileName);

        return redirect()->back()->with('success', 'File uploaded successfully.');
    }

    // ...
}
Zany Zebra

Tampilkan file PDF di Laravel

Route::get('/pdf/{file}', function ($file) {
      // file path
     $path = public_path('storage/file' . '/' . $file);
      // header
     $header = [
       'Content-Type' => 'application/pdf',
       'Content-Disposition' => 'inline; filename="' . $file . '"'
     ];
    return response()->file($path, $header);
})->name('pdf');
Dev Arman

Jawaban yang mirip dengan “Tampilkan file PDF di Laravel”

Pertanyaan yang mirip dengan “Tampilkan file PDF di Laravel”

Lebih banyak jawaban terkait untuk “Tampilkan file PDF di Laravel” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya