PHP强制下载远程文件 [英] PHP Force Download of Remote File
问题描述
我想使用这样的东西:
;?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屋!