Ok, let me clarify this:
- You are using include() to include via a URL. This smells bad to me - it smells either of not understanding what include() does on remote files, or self-writing code (which I don't like).
If that's the whole of getremotefile.php, then it's even more weird, as it doesn't appear to be echo'ing anything - therefore you're including an empty file - so include() as an RPC mechanism? A bit strange, I think, in the extreme.
You have a script called getremotefile.php which seems to be doing more or less the opposite - it's actually used to PUT a remote file. But not quite,
It's an obfuscated callback mechanism - there are three HTTP requests happening concurrently, when surely a maximum of two are required?
You're relying on the file being in a directory served by the web server are you? This is totally unclear.
I think it is obfuscated. You're abusing include() to do something totally different. You're making three requests instead of two, and this is probably totally unclear to most people (indeed, it was to me before I looked at it more carefully).
I'm going to offer an alternative implementation here:
<?php
function TestSend()
{
$filename = "test.txt";
$url = "http://localhost:9001/put.php?filename=" . urlencode($filename);
$content = file_get_contents($filename);
$opts = array ('http' => array (
'method' => 'POST',
'content' => $content,
'header' => "Content-type: application/octet-stream"));
$ctx = stream_context_create($opts);
$f = fopen($url, "r", false /* use_include_path*/, $ctx);
$result = stream_get_contents($f);
fclose($f);
echo "Post result: $result\n";
}
TestSend();
?>
<?php
/*
* Recieve a remote file via a raw HTTP POST.
*
* Security NOTE: this should do some authorisation and
* perform better checks on the filename.
*/
function DoPut()
{
$filename = $_GET['filename'];
// Some lame checks - NOT SUITABLE FOR PRODUCTION USE!
assert(strchr($filename, '/') === FALSE);
assert(strchr($filename, "\\") === FALSE);
assert(strchr($filename, '.php') === FALSE);
global $HTTP_RAW_POST_DATA;
assert(isset($HTTP_RAW_POST_DATA));
$f = fopen("uploads/" . $filename, "wb");
fwrite($f, $HTTP_RAW_POST_DATA);
fclose($f);
echo "ok";
}
DoPut();
?>
I've tested this in a recent PHP 5.1.2+ snapshot version and it appears to work. Your mileage may vary, but the above is tested and requires only two HTTP requests, not three.
I'm using raw post data to send the file.
Mark