$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);
您好,我是snikolov我正在使用PHP创建一个miniwebserver,我想知道我可以发送客户端要下载的文件与他的浏览器,如Firefox或Internet浏览我发送一个文件给用户通过套接字下载,但cleint没有得到文件名和信息下载可以请你帮我在这里,如果我再次声明文件我得到这个错误在我的服务器
致命错误 :无法重新声明openfile()(以前在C:\ User s \ fsfdsf \ sfdsfsdf \ httpd.php:31中声明) C:\用户\ hfghfgh \ hfghg \ httpd.php李 NE
,如果可能的话,我想知道,如果网络服务器能表现出多大的banwdidth通过套接字的用户请求,Perl有相同的选项作为PHP,但它的核心比PHP我更了解perl,我甚至看到miniwebserver可以显示很多客户端用户从服务器上拉出来,有可能你可以用这种编码来帮助我,我非常赞赏它谢谢家伙。
你设法把整个后一句话;) – 2010-05-31 09:59:12