替代READFILE()READFILE

2023-09-11 23:45:25 作者:间歇性精神病

我目前使用下面的code,从我的Amazon S3帐户下载的文件。

I'm currently using the following code to download files from my Amazon S3 account.

if(isset($_POST['file_name'])) {
$bucket = $_POST['bucket'];
$fname = $_POST['file_name'];
$accessKey = 'AKIAIEHFBME6F5Q62FTQ';
$secretKey = '<REMOVED>';
$file_type = pathinfo($fname, PATHINFO_EXTENSION);

$mp3_url = el_s3_getTemporaryMP3Link($accessKey, $secretKey, $bucket, $fname);    
$zip_url = el_s3_getTemporaryZipLink($accessKey, $secretKey, $bucket, $fname);


if ($file_type === "mp3") {
    header('Content-type: audio/mpeg3');
    header('Content-Disposition: attachment; filename="themixtapesite_'.$fname.'"');
    readfile($mp3_url);
    exit();
} else if ($file_type === "zip") {
    header('Content-type: application/zip');
    header('Content-Disposition: attachment; filename="themixtapesite_'.$fname.'"');
    readfile($zip_url);
    exit();
} else {
    echo "Sorry, File does not exist";
}

}

正如你可以看到它会检查一下文件的扩展名,然后通过相关的URL中读取文件()

As you can see it checks what the file extension is then passes the relevant url in to read file()

使用S3我的全部意义在于减轻我的EC2服务器负载。 但是,似乎用这种方法来下载拉动从S3文件通过EC2服务器(监视服务器的负载,通过国家统计局显示我的活动增加下载文件时)的文件。

The whole point of me using S3 is to lighten my EC2 server loads. However, it seems using this method to download the files it pulling the files from S3 via the EC2 server (monitoring the server loads via iStat shows me an increase in activity when downloading a file).

是否有这样做这样的文件直接从S3,而不是通过EC2服务器??

Is there an alternative way of doing this so the file is downloaded directly from S3 rather than via the EC2 server??

更新:只是一个快速更新 - 我使用Nginx的,而不是阿帕奇所以没有的.htaccess,如果有人在想这表明

UPDATE: Just a quick update - I'm using Nginx rather than apache so no .htaccess if anybody was thinking of suggesting that.

推荐答案

如果你有一个公开访问的URL,或签名网址。可以使用一个位置重定向直接传递到客户端。

If you have a publicly accessible url, or signed url. You can pass that directly to the client using a location redirect.

头('位置:'。$ myUrl);

相关推荐