Как отдать на загрузку какой-либо файл на сервере с помощью php

В редакторе

Как отдать на загрузку какой-либо файл на сервере с помощью php

Brain_Script
875
2018-12-11 20:03:59
function download ($file) { if (!empty($file) and file_exists($file) and is_file($file)) { if (ob_get_level()) { ob_end_clean(); } 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'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); if ($fd = fopen($file, 'rb')) { while (!feof($fd)) { print fread($fd, 1024); } fclose($fd); } } else { header('HTTP/1.0 404 Not Found'); echo 'File not found'; } exit(); }
Войдите для добавления комментария.
Нет комментариев
Яндекс.Метрика Яндекс.Метрика