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

时间:2013-08-08 05:46:33

标签: php curl upload

我有以下脚本

    <?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?

1 个答案:

答案 0 :(得分:0)

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