Untenstehender Code funktioniert. Request PHP:
$host = "example";
$port = 80;
$file = "d:/tmp/red.gif";
$content = file_get_contents($file);
$url = sprintf("%s?filename=%s", "/getpost.php", urlencode(basename($file)));
$len = strlen($content);
$socket = fsockopen($host, $port);
fputs($socket,"PUT $url HTTP/1.0\n");
fputs($socket,"Content-Length: $len\n");
fputs($socket, "Host: $host\n\n");
fputs($socket, $content);
# Response ausgeben
while(!feof($socket)) {
echo fgets($socket, 128);
}
Serverseitig PHP:
header("Content-Type: text/plain");
echo "Anzahl Bytes gesendet: ", $_SERVER{'CONTENT_LENGTH'}, "\n\n";
print_r($_GET);
$body = file_get_contents("php://input");
echo "BODY:\n", $body;
# Datei probeweise anlegen
$filename = $_GET['filename'];
$fp = fopen("d:/tmp/upload/$filename", "wb");
fputs($fp, $body);
(Ohne Fehlerbehandlung, ohne Auth.Baisc)
PS: Alternative RequestMethod: fputs($socket,"Zitrone $url HTTP/1.0\n");