Skip to content

Instantly share code, notes, and snippets.

@helart
Created August 21, 2020 16:14
Show Gist options
  • Save helart/8a30089c629db2f852d30e53b5cd2f26 to your computer and use it in GitHub Desktop.
Save helart/8a30089c629db2f852d30e53b5cd2f26 to your computer and use it in GitHub Desktop.
Отдача файлов на скачивание PHP
<?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