简体   繁体   English

PHP 强制下载 Amazon S3 链接

[英]PHP force download of Amazon S3 link

I have the following 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.但是,当单击执行此代码的下载链接时,它总是返回一个 0 字节的文件。 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? .mp3扩展名真的不是文件名的一部分,因为它存储在 S3 上吗?

You're appending .mp3 to the filename in the Content-Disposition header, but not the URL you're passing to readfile .您将.mp3附加到 Content-Disposition header 中的文件名,但不是 URL 传递给readfile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM