drti52047 2015-10-11 16:59
浏览 114
已采纳

从另一台服务器下载文件的旁路服务器php代码

My situation is illustrated in the figure below:

I have a file X on the main server A which I want to download from my local computer B and the file X is downloadable through HTTP. But, for some reason I am not allowed to download file from the main server A. However, I have an access to another server C which has PHP installed. I now want to download the file X via the server C by calling some PHP script on server C from my local computer B.

Is it possible to write one PHP script to do the above?

Any help in writing so will be highly appreciated.

  • 写回答

1条回答 默认 最新

  • duanguanye4124 2015-10-11 17:19
    关注

    I'm not completely sure of what you need but you can use the following script to act as proxy between 2 servers.

    PUT THIS FILE ON SERVER C

    phpProxy.php

    <?php
    $myPass = "Secr3t";
    if( $myPass == $_GET['pass'] ){
        $remoteFile = $_GET['rf'];
        $filename = basename( $remoteFile );
        header("Content-Type: application/octet-stream");
        header("Content-Disposition: attachment; filename=\"$filename\"");
        echo file_get_contents( $remoteFile );
    }
    

    USE AS:

    phpProxy.php?rf=http://phs.googlecode.com/files/Download%20File%20Test.zip&pass=Secr3t
    

    NOTES:
    1 - I've added a password otherwise the script is very unsafe!
    2 - If possible, use https to avoid MITM

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试