Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọcheader[] function in php. The header[]function is used to send a raw HTTP header. Sometimes it wants the user to be prompted to save the data such as generated PDF.
Syntax:
header["Content-Type: application/octet-stream"];
header['Content-Disposition: attachment; filename="downloaded.pdf"'];
header["Content-Length: " . filesize["download.pdf"]];
header['Content-Disposition: attachment; filename="downloaded.pdf"'];
readfile['original.pdf'];
Độ dài của tệp được yêu cầu cần tải xuống ____2
Đọc một tệp và ghi nó vào bộ đệm đầu ra .________ 3 Remember that HTTP header[] must be called before any actual output is sent, either by normal HTML tags, blank lines in a file or from PHP.
. Save below HTML file as htmllinkpdf.html and save PHP file as downloadpdf.php
- Lưu ý: Hãy nhớ rằng tiêu đề HTTP [] phải được gọi trước khi bất kỳ đầu ra thực tế nào được gửi, bằng các thẻ HTML thông thường, các dòng trống trong một tệp hoặc từ PHP.
- Ví dụ 1: Lưu bên dưới tệp HTML dưới dạng htmllinkpdf.html và lưu tệp php dưới dạng tải xuống
- Dưới đây ví dụ để minh họa khái niệm tải xuống tệp PDF bằng liên kết HTML.
header['Content-Disposition: attachment; filename="downloaded.pdf"'];
1header['Content-Disposition: attachment; filename="downloaded.pdf"'];
7head
>
header['Content-Disposition: attachment; filename="downloaded.pdf"'];
1Ở đây tải xuống tệp dường như là định dạng PDF nhưng không có bất kỳ nội dung nào hiển thị lỗi khi mở trong bất kỳ ứng dụng nào
header["Content-Length: " . filesize["download.pdf"]];
7header["Content-Length: " . filesize["download.pdf"]];
7header['Content-Disposition: attachment; filename="downloaded.pdf"'];
7readfile['original.pdf'];
8>
Mã HTML:
header['Content-Disposition: attachment; filename="downloaded.pdf"'];
7header["Content-Length: " . filesize["download.pdf"]];
1>
header['Content-Disposition: attachment; filename="downloaded.pdf"'];
7html
>
header["Content-Length: " . filesize["download.pdf"]];
70
>
1______72head
3- Output:
6
header["Content-Length: " . filesize["download.pdf"]];7