我正在努力实现这一切
我有一个 PHP 文件index.php
运行在客户端上传文件的 Web 服务器 (WAS) 上。
我有另一台足够强大的服务器(GPU)来处理这些文件。
我的用例是,客户上传通过a发送的图像POST
请求index.php
。现在,它必须将文件发送到另一台服务器 (GPU),并在 GPU 上发送另一个 PHP 文件,例如process.php
必须拍摄该图像并对其进行处理。
到目前为止,我认为我可以用 PHP 实现上述内容cURL
图书馆。
我的问题主要是如何将处理后的图像返回给客户端?
我该如何制作process.php
将处理后的图像发送回index.php
并将其返回给客户?
这必须是一项例行任务,但我将不胜感激在实施此任务时提供的任何帮助。
代码为index.php
,我将文件存储在网络服务器上,因为处理完成后我需要显示比较(之前/之后)。我还没有实施process.php
<?php
$ds = DIRECTORY_SEPARATOR;
$storeFolder = 'uploads';
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$targetFile = $targetPath. $_FILES['file']['name'];
move_uploaded_file($tempFile,$targetFile);
}
function cURLcheckBasicFunctions() {
if( !function_exists("curl_init") &&
!function_exists("curl_setopt") &&
!function_exists("curl_exec") &&
!function_exists("curl_close") ) return false;
else return true;
}
if( !cURLcheckBasicFunctions() )
{ echo "UNAVAILABLE: cURL Basic Functions"; }
// $url = "129.132.102.52/process.php";
$url = "dump_test.php";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST, 1);
$fp = fopen($targetFile, "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$reply = curl_exec($ch);
curl_close($ch);
fclose($fp);
echo $_FILES['file']['name'];
?>