Home>

I am not an expert in HTML and PHP, but I need to implement the following task: add the ability to download mp3 files to the site directly (without playing through the browser). Found a way to use a php file. The problem is that the larger the file size, the longer it will take to start downloading; and if the file size is > 200 MB php error drops. How can you fix this problem? Maybe there are more suitable options besides using a php file ... Thanks.

HTML:

<
a href= "d.php? file= http: //remoteserver/1.mp3" >
Download <
/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 ();
    }
? >

Have you tried looking at file proxying through NGINX?

Дмитрий Мирошниченко2022-01-11 14:48:45