502 Bad Gateway When Using Header Content-Length

I am trying to force the browser to download an mp3 when the user visits this site. The issue I am running into is if i set the Content-Length header the page throws a 502 Bad Gateway error, and if I don’t it attempts to download the file, but the file is 0 bytes in size. The site happens to be running wordpress. Any direction would be really appreciated. I am not familiar with wordpress.

    $file = '../uploads/2015/01/Thunder.mp3';
    header('Content-type: application/mp3');
    header("Content-Disposition: attachment; filename="$file"");
    header('Content-Length: '.filesize($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');

Related posts

1 comment

Comments are closed.