I am trying to implement all of this in
I have a PHP file index.php running on a webserver (WS) on which clients upload files.
I have another server which is powerful enough (GPUs) to process these files.
My use case is, clients upload images which are sent via a POST request to index.php. Now, it has to send the file to another server (GPU) and on GPU, another PHP file, say process.php has to take this image, process it.
So far, I think I can implement the above with PHP's cURL library.
My question is mostly about how do I get the processed image back to the client?
How do I make process.php send back the processed image to index.php and get it back to the client?
This must be a routine task but I would appreciate any help in implementing this.
code for index.php, I am storing the file on the webserver because I need to show a comparison (Before / After) once the processing is done. I have not yet implemented 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'];
?>
$reply = curl_exec($ch);.POSTrequest again? I am not sure of how I could get theprocess.phpto send the image.process.phpto process the image, and when it's done with the process, it echoes the final image and exits. The processed image is therefore sent as the request response, so you will get it as the result of the curl request in WS, where you can store the image, send it back to the client, or etc. Does this makes sense? heh. I could write snippets to help with the picture if you want.it echoes the final imagepart. Would that be likeecho <img src=...? In any case, if you could write the snippets as an answer, I'd happily accept it!