PHP Alternative Upload image method (PHP with socket upload image)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.