PHP强制下载远程文件 [英] PHP Force Download of Remote File

查看:136
本文介绍了PHP强制下载远程文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一大堆存储在我的Amazon S3存储上的视频。我正在创建一个非常类似于的PHP脚本,用户可以将视频下载到他们的硬盘。



我想使用这样的东西:

  ;?php 
$ file_name = $ _GET ['file'];
$ file_url ='http://www.myamazons3.com/'。 $ FILE_NAME;
header('Content-Type:application / octet-stream');
header(Content-Transfer-Encoding:Binary);
header(Content-disposition:attachment; filename = \$ file_name。\);
readfile($ file_url);
退出;

但是,我的印象是这会增加带宽,因为视频将通过我的服务器



有什么想法可以强制下载这些视频,同时避免首先通过我自己的服务器阅读?



非常感谢!

解决方案

查看S3 API文档,并记下您可以设置的标题值。当请求文件时,亚马逊将发送这些文件: http:// docs。 aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html (可以使用POST发送相同的参数来更新现有对象)


I have a bunch of videos stored on my Amazon S3 storage. I'm working on creating a PHP script, very similar to the one here, where users can download the videos to their hard drive.

I'd like to use something like this:

<?php
$file_name = $_GET['file'];
$file_url = 'http://www.myamazons3.com/' . $file_name;
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"".$file_name."\""); 
readfile($file_url);
exit;

However, I am under the impression that this increases the bandwidth because the video will be coming through my server.

Any ideas on how I might be able to force the download of these videos, while avoiding reading it first through my own server?

Many thanks!

解决方案

Take a look at the S3 API Docs, and note the header values that you can set. Amazon will send these when the file is requested: http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html (the same parameters can be sent with a POST to update an existing object)

这篇关于PHP强制下载远程文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆