Hướng dẫn how to force download file in php? - làm thế nào để buộc tải xuống tệp trong php?

Tôi đang tìm cách thêm chức năng "Tải xuống tệp này" bên dưới mọi video trên một trong các trang web của tôi. Tôi cần buộc người dùng tải xuống tệp, thay vì chỉ liên kết với nó, vì đôi khi điều đó bắt đầu phát một tệp trong trình duyệt. Vấn đề là, các tệp video được lưu trữ trên một máy chủ riêng biệt.

Bất cứ cách nào tôi có thể buộc tải xuống trong PHP?

document.querySelector['a'].click[];

Đã trả lời ngày 20 tháng 8 năm 2019 lúc 8:21Aug 20, 2019 at 8:21

download

.htaccess

Options -Indexes
Options +FollowSymlinks
deny from all

download.php

$file = "pdf/teste.pdf";
 if [file_exists[$file]] {
    header['Content-Description: File Transfer'];
    header['Content-Type: application/octet-stream'];
    header['Content-Disposition: attachment; filename='.basename[$file]];
    header['Content-Transfer-Encoding: binary'];
    header['Expires: 0'];
    header['Cache-Control: must-revalidate, post-check=0, pre-check=0'];
    header['Pragma: public'];
    header['Content-Length: ' . filesize[$file]];
    ob_clean[];
    flush[];
    readfile[$file];
    exit[];
}

Đã trả lời ngày 19 tháng 6 năm 2020 lúc 21:43Jun 19, 2020 at 21:43

1

Bài Viết Liên Quan

Chủ Đề