【问题标题】:How to forward the post file to an other server to the same script如何将发布文件转发到其他服务器到同一脚本
【发布时间】:2023-03-25 11:22:01
【问题描述】:

我有以下脚本

    <?php 

$target_path = $_SERVER[DOCUMENT_ROOT]."/files/cache/";


$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { 
    echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded"; 
} else{ 
    echo "There was an error uploading the file, please try again!"; 
}

?> 

我喜欢这样修改,文件上传到服务器A,服务器A上的脚本调用这个脚本,你可以在这里看到,在服务器B上,因为我不能直接调用这个脚本。

这看起来怎么样? 在服务器 B 上,很明显,我会使用顶级脚本。但我必须考虑服务器 A 上的脚本。

我想我必须使用函数 file_get_contents(...) 从服务器 A 调用服务器 B 上的脚本

    <?php 

$target_path = $_SERVER[DOCUMENT_ROOT]."/files/cache/";


$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { 
    echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded"; 
} else{ 
    echo "There was an error uploading the file, please try again!"; 
}
//Start upload to server  B
file_get_contents("http://server2.com/upload.php");

//...
//But here I have to add the post data-File
?> 

但是如何使用file_get_contents() 或其他任何东西来解析 Post-File?

【问题讨论】:

    标签: php curl upload


    【解决方案1】:

    您无法从其他服务器获取代码文件。可能你必须改变逻辑并使用 ajax。

    【讨论】:

      猜你喜欢
      • 2021-11-12
      • 2016-04-14
      • 2021-02-19
      • 2020-05-26
      • 2012-01-03
      • 1970-01-01
      • 2013-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多