douwei1408 2014-08-28 14:02
浏览 49
已采纳

通过亚马逊s3 php类强制下载文件

My application is using tpyo/amazon-s3-php-class to put and get objects to/from Amazon S3 storage.

Files are not available publicly and I want my users to be able to download private files through my application.

amazon-s3-php-class offers two options to get the file:

  1. Save an object to file: S3::getObject($bucketName, $uploadName, $saveName)
  2. Save an object to a resource of any type: S3::getObject($bucketName, $uploadName, fopen('savefile.txt', 'wb'))

But both methods save a file to my web server. How can I force file download to a client's computer?

  • 写回答

1条回答 默认 最新

  • doulao2128 2014-08-28 14:10
    关注

    I believe you could use the second option, passing the output buffer as the filename argument for fopen (after setting the correct headers):

    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    //etc etc
    
    S3::getObject($bucketName, $uploadName, fopen('php://output', 'wb'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题