$httpsock = @socket_create_listen("9090"); if (!$httpsock) { print "Socket creation failed!\n"; exit; } while (1) { $client = socket_accept($httpsock); $input = trim(socket_read ($client, 4096)); $input = explode(" ", $input); $input = $input[1]; $fileinfo = pathinfo($input);
switch ($fileinfo['extension']) { default: $mime = "text/html"; } if ($input == "/") { $input = "index.html"; } $input = ".$input"; if (file_exists($input) && is_readable($input)) { echo "Serving $input\n"; $contents = file_get_contents($input); $output = "HTTP/1.0 200 OK\r\nServer: APatchyServer\r\nConnection: close\r\nContent-Type: $mime\r\n\r\n$contents"; } else { //$contents = "The file you requested doesn't exist. Sorry!"; //$output = "HTTP/1.0 404 OBJECT NOT FOUND\r\nServer: BabyHTTP\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n$contents"; function openfile() { $filename = "a.pl"; $file = fopen($filename, 'r'); $filesize = filesize($filename); $buffer = fread($file, $filesize); $array = array("Output"=>$buffer,"filesize"=>$filesize,"filename"=>$filename); return $array; } $send = openfile(); $file = $send['filename']; $filesize = $send['filesize']; $output = 'HTTP/1.0 200 OK\r\n'; $output .= "Content-type: application/octet-stream\r\n"; $output .= 'Content-Disposition: attachment; filename="'.$file.'"\r\n'; $output .= "Content-Length:$filesize\r\n"; $output .= "Accept-Ranges: bytes\r\n"; $output .= "Cache-Control: private\n\n"; $output .= $send['Output']; $output .= "Content-Transfer-Encoding: binary"; $output .= "Connection: Keep-Alive\r\n"; } socket_write($client, $output); socket_close ($client);
} socket_close ($ httpsock);
안녕하세요, 나는 내가 PHP와 miniwebserver을 만드는 오전과 내가 클라이언트에게 내가 보내고 탐구 파이어 폭스 또는 인터넷으로 자신의 브라우저를 다운로드 할 수있는 파일을 보낼 수있는 방법을 알고 싶습니다 snikolov 사용자가 파일을 소켓을 통해 다운로드 할 수 있지만 클린턴 파일 이름 및 다운로드 할 정보를 얻지 못하고 있습니다. 만약 내가 파일을 다시 선언하면 내 서버에이 오류가 발생합니다.
치명적인 오류 : openfile() (이전에 C : \ User s \ fsfdsf \ sfdsfsdf \ httpd.php : 31에 선언 된)을 다시 선언 할 수 없습니다. C : 사용자 \ \ hfghfgh \ hfghg \ httpd.php는 리튬 네브라스카 29
, 그것의 가능한 경우, 내가 웹 서버는 소켓을 통해 사용자 요청 banwdidth 많이 보여줄 수 있는지 알고 싶습니다에, 펄 같은 옵션이 있습니다 하지만 PHP보다 더 많은 하드 코어는 펄에 대해 많이 이해하지 못한다. 심지어 미니 웹 서버는 클라이언트 사용자가 서버에서 가져온 것을 많이 보여줄 수 있다는 것을 알았다.이 코딩으로 나를 도와 줄 수 있었으면 좋겠다. 얘들 아.
, 내가 cleint 파일을 다운로드 할 때 대역폭을 볼 수있을 것입니다 방법을 알고 싶습니다) –