开发者

PHP force download of Amazon S3 link

开发者 https://www.devze.com 2023-03-09 23:25 出处:网络
I have the foll开发者_JS百科owing code header(\"Content-Description: File Transfer\"); header(\'Content-Type: audio/mp3\');

I have the foll开发者_JS百科owing code

        header("Content-Description: File Transfer");
        header('Content-Type: audio/mp3');
        header("Content-Disposition: attachment; filename=" . $arrResults['audioLink'] . ".mp3");
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header("Content-Transfer-Encoding: binary");

        $strLink = 'http://ag-org.s3.amazonaws.com/members/tele_classes/' . $arrResults['audioLink'];

        ob_clean();
        flush();
        readfile($strLink);

However when the download link is clicked that executes this code it always returns a 0 byte file. All files are set to public in the bucket.

What am I doing wrong here?


Is the .mp3 extension really not part of the filename as it's stored on S3?

You're appending .mp3 to the filename in the Content-Disposition header, but not the URL you're passing to readfile.

0

精彩评论

暂无评论...
验证码 换一张
取 消