简体   繁体   中英

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. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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