简体   繁体   中英

force download file from s3 using php

I want to download the file directly from s3 to user machine. So I have googled and came up with something like this. But this is not working.

$objInfo = $s3->getObjectInfo('bucket', 'filename.mp3');
$obj = $s3->getObject('bucket', 'filename.mp3');

header('Content-type: ' . $objInfo['type']);
echo $obj->body;

How to force download file not based on URL from s3.

try adding

Content-Disposition: attachment

to the header, optionally you can also specify the filename for the file being downloaded with

Content-Disposition: attachment; filename=somefile.ext 

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