Created
August 21, 2020 16:14
-
-
Save helart/8a30089c629db2f852d30e53b5cd2f26 to your computer and use it in GitHub Desktop.
Отдача файлов на скачивание PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Отправка заголовков | |
$file = __DIR__ . '/file.avi'; | |
header('Content-Description: File Transfer'); | |
header('Content-Type: video/x-msvideo'); | |
header('Content-Disposition: attachment; filename=' . basename($file)); | |
header('Content-Transfer-Encoding: binary'); | |
header('Content-Length: ' . filesize($file)); | |
// Второй, application/octet-stream – «двоичный файл без указания формата». | |
$file = __DIR__ . '/file.avi'; | |
header('Content-Description: File Transfer'); | |
header('Content-Type: application/octet-stream'); | |
header('Content-Disposition: attachment; filename=' . basename($file)); | |
header('Content-Transfer-Encoding: binary'); | |
header('Content-Length: ' . filesize($file)); | |
// Полный пример | |
ob_end_clean(); | |
$file = __DIR__ . '/file.avi'; | |
header('Content-Description: File Transfer'); | |
header('Content-Type: application/octet-stream'); | |
header('Content-Disposition: attachment; filename=' . basename($file)); | |
header('Content-Transfer-Encoding: binary'); | |
header('Content-Length: ' . filesize($file)); | |
readfile($file); | |
exit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment