通过脚本从文件服务器下载文件


Download File from File-Server via Script

我有三个文件服务器,想要为文件下载添加一个"透明层"(一个脚本被执行,获取文件并直接发送给用户)。

用户应该只使用一个链接访问一个文件,例如:

www.mysite.com/download/<UUID_WITH_correctFileServer>

我现在要问的问题是:

  • 是否有可能为用户提供一个性能良好的单一访问url(如上述)?
  • 我认为只使用一个java-servlet或php-脚本的性能不如在每个文件服务器上有一个脚本->我的猜测:文件是从文件服务器发送到中央脚本,从那里到用户。正确吗?
  • 其他云存储提供商是如何解决这个问题的?

天哪…会……只有第一个文件在例子中实际工作,好吗?

如果你不关心导航,你可以这样做:

test.php

<?php 
if(isset($_GET['fname']) and $_GET['fname']){
    // do something with filename to decide from where to donwload
    if($_GET['fname']=="DWSM_Domain.png") header("Location: ftp://anonymous:test@mailinator.com@ftp.swfwmd.state.fl.us/pub/CFWI_HAT/DWSM_Domain.png");  
    if($_GET['fname']=="file1") header("Location: ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file1");
    if($_GET['fname']=="file2") header("Location: ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file2");
    exit;
} 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
</head>
<body>
    <p><a href="/test.php?fname=DWSM_Domain.png">DWSM_Domain.png</a></p>
    <p><a href="/test.php?fname=file1">file1</a></p>
    <p><a href="/test.php?fname=file2">file2</a></p>
</body>

如果你想让用户打开另一个窗口,你将需要两个php文件。

test1.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript" src="/js/jquery.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
</head>
<body>
    <p><label onclick="get_file('DWSM_Domain.png')">DWSM_Domain.png</label></p>
    <p><label  onclick="get_file('file1')">file1</label></p>
    <p><label  onclick="get_file('file2')">file2</label></p>
    <script>
        function get_file(thisfile) {
            if(thisfile){
                var content;
                var page = "/test2.php?fname="; 
                var address = page.concat(thisfile);
                $.get(address, function (data) {
                    content = data;
                    var newWindow = window.open("","_blank");
                    newWindow.location.href = content;
                });
            } 
        }
    </script>
</body>

test2.php

<?php 
    if(isset($_GET['fname']) and $_GET['fname']){
        // do something with filename to decide from where to donwload
        if($_GET['fname']=="DWSM_Domain.png") $targetfile ="ftp://anonymous:test@mailinator.com@ftp.swfwmd.state.fl.us/pub/CFWI_HAT/DWSM_Domain.png";   
        if($_GET['fname']=="file1") $targetfile ="ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file1";
        if($_GET['fname']=="file2") $targetfile ="ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file2";
        echo $targetfile;
    }
?>

你当然需要驯服它来得到你确切的行为,但我希望这是一个好的开始。公平的风

是的,这是可能的,但这取决于您托管脚本的服务器的性能,以及用户的互联网连接