


Alternative method of uploading pictures in php (PHP uses Socket to upload pictures)_PHP tutorial
Jul 13, 2016 am 10:25 AM
Server side:
<?php
set_time_limit( 10);
//* Set not to display 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 "Listening successful";
}
}
}else{
echo "Monitoring failed";
}
//$path = "/home/upload/";
$path = "e://web//";
while (true) {
$connection = socket_accept($socket);
if($connection){
$msg = "telnet succeed!rn";
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);
?> ;
$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 successful";
}
}
fclose($fp);
?>

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon
