如何将post文件转发到同一脚本的其他服务器


How to forward the post file to an other server to the same script

我有以下脚本

    <?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上的脚本。

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

    <?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文件呢?

您无法从其他服务器获取代码文件。您可能需要更改逻辑并使用ajax。

相关文章: