$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