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

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

问题描述

我有一大堆的存储在我的亚马逊S3存储的视频。我正在创建一个PHP脚本,非常类似于在这里一个 ,用户可以将视频下载到自己的硬盘。

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.

我想用这样的:

<?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;

不过,我在IM pression,这增加了带宽,因为视频将通过我的服务器到来。

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?

非常感谢!

推荐答案

看看S3的API文档,请注意,您可以设置标题值。当请求文件为亚马逊将发送这些: HTTP://docs.aws .amazon.com / AmazonS3 /最新/ API / RESTObjectPUT.html (相同的参数可以用邮寄来更新现有对象)

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天全站免登陆