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 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大