Server-side: . the code is as follows:
<?php
Set_time_limit (10);
* Settings do not show any errors */
error_reporting (0);
function Varinfo ($STR) {
echo "<PRe>";
Var_dump ($STR);
echo "<pre>";
}
$commonProtocol = Getprotobyname ("TCP");
$socket = Socket_create (Af_inet, Sock_stream, $commonProtocol);
if ($socket) {
$result = Socket_bind ($socket, ' 192.168.3.57 ', 1337);
if ($result) {
$result = Socket_listen ($socket, 5);
if ($result) {
echo "Monitor success";
}
}
}else{
echo "Monitor failed";
}
$path = "/home/upload/";
$path = "e://web//";
while (true) {
$connection = Socket_accept ($socket);
if ($connection) {
$msg = "Telnet succeed!\r\n";
Socket_write ($connection, $msg, strlen ($msg));
$BufferPond = Array ();
$buffer = ";
while ($flag = Socket_recv ($connection, $buffer, 1024, 0)) {
if (False!== Strpos ($buffer, ' filename: ')) {
$filename = substr ($buffer, 9);
$filename = $path. $filename;
$fp = fopen ($filename, "WB");
Continue
}
Fwrite ($fp, $buffer);
}
Fclose ($FP);
Socket_close ($connection);
}
}
Socket_close ($socket);
?>
Client:
. the code is as follows:
<?php
$errno = ' 001 ';
$ERRSTR = "Socket file error"; $fp = Fsockopen ("192.168.3.57", 1337, $errno, $ERRSTR, 10);
if (! $fp) {
echo "$errstr ($errno) <br/>\n";
} else {
$str = "Filename:socket_file.bmp";
Fwrite ($fp, $STR); $out = file_get_contents ('.. /.. /iphone3g.bmp ');
if ($out) {
Fwrite ($fp, $out);
Fwrite ($fp, ' over ');
echo "Upload success";
}
}
Fclose ($FP);
?>
PHP Alternative Upload image method (PHP with socket upload image)