Как заставить php force загрузить файл. У меня есть файл с именем song1, который является песней, в файлах песен. поэтому со страницы, на которой я нахожусь, это песня/song1. Как заставить php загружать файл сразу после запуска php?PHP force download
0
A
ответ
1
Вы должны отправить некоторые заголовки HTTP:
header('Content-disposition:attachment; filename=song.mp3;');
Тогда вы должны вытащить данные песни с, например file_get_contents()
. И, наконец, используйте die()
или exit()
, чтобы избежать добавления дополнительных данных.
Примечание: приведенный выше код не будет работать, если вы уже отправили HTTP-заголовки (выписали некоторые пробельные символы и т. Д.), Поэтому поместите его непосредственно после <?php
, если сможете.
0
Try ниже код
$file='song1.mp3';
if (file_exists('song/'.$file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename('song/'.$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('song/'.$file));
ob_clean();
flush();
readfile('song/'.$file);
}
Он будет напрямую загрузить файл.
Смежные вопросы
- 1. php force download headers
- 2. PHP force download не работает?
- 3. Force file download in php
- 4. PHPExcel Force Download Issue
- 5. force download script
- 6. php script to force download youtube video
- 7. php force download показывает мусор на экране
- 8. PHP Force Download Causeing 0 Байт файлов
- 9. PHP Force File Download Code - Ошибка
- 10. Force file download in php не работает
- 11. Force image download - .php files загрузить
- 12. Использование PHP force download для всех файлов
- 13. PHP CSV create and force download
- 14. php force download script больше не работает
- 15. force pdf download on openshift с php
- 16. force download using ZF2
- 17. Force file download header
- 18. Force download не работает
- 19. Force download image
- 20. cakePHP force download of ical
- 21. Codeigniter Force download не работает
- 22. Force download on Mongoose Server
- 23. Force file download AND показать новую страницу
- 24. Force download and htaccess = zero bytes files
- 25. Cocoa - application/force-download и NSURLConnection
- 26. Проблемы с putcsv и force-download
- 27. Idiot-proof, cross-browser force download in PHP
- 28. PHP Force Download - дает файлы в 190 байт
- 29. PHP force download, не отправляя полные двоичные файлы
- 30. getContentType метод return always 'application/force-download'