I am not a specialist in HTML and PHP, but I need to implement the following task: add the ability to download mp3 files directly to the site (without playback through the browser). Found a way to use php-file. The problem is that the larger the file size, the longer the wait to start downloading; and if the file size is> 200 MB, a php error occurs. How can I fix this problem? Maybe there are more suitable options besides using a php file ... Thank you.
HTML:
<a href="d.php?file=http://remoteserver/1.mp3">Скачать</a> d.php:
<?php $file = $_GET['file']; $file = str_replace(' ', '%20', $file); $ch = curl_init($file); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_NOBODY, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); $output = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($status == 200) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($file).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . strlen($output)); echo $output; die(); } ?>