Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 826081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:21:27+00:00 2026-05-15T03:21:27+00:00

$httpsock = @socket_create_listen(9090); if (!$httpsock) { print Socket creation failed!\n; exit; } while (1)

  • 0

$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);

Hello, I am snikolov i am creating a miniwebserver with php and i would like to know how i can send the client a file to download with his browser such as firefox or internet explore i am sending a file to the user to download via sockets, but the cleint is not getting the filename and the information to download can you please help me here,if i declare the file again i get this error in my server

Fatal error: Cannot redeclare openfile() (previously declared in C:\User
s\fsfdsf\sfdsfsdf\httpd.php:31) in C:\Users\hfghfgh\hfghg\httpd.php on li
ne 29
, if its possible, i would like to know if the webserver can show much banwdidth the user request via sockets, perl has the same option as php but its more hardcore than php i dont understand much about perl, i even saw that a miniwebserver can show much the client user pulls from the server would it be possible that you can assist me with this coding, i much aprreciate it thank you guys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:21:28+00:00Added an answer on May 15, 2026 at 3:21 am

    You are not sending the filename to the client, so how should it know which filename to use?

    There is a drawback, you can provide the desired filename in the http header, but some browsers ignore that and always suggest the filename based on the last element in URL.
    For example http://localhost/download.php?help.me would result in the sugested filename help.me in the file download dialogue.

    see: http://en.wikipedia.org/wiki/List_of_HTTP_headers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 418k
  • Answers 418k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For anyone interested I've just stumbled apon an answer to… May 15, 2026 at 9:57 am
  • Editorial Team
    Editorial Team added an answer Everything is right, except the glVertexAttribPointer call. When you have… May 15, 2026 at 9:57 am
  • Editorial Team
    Editorial Team added an answer I suggest looking at using MSDeploy, which packages up all… May 15, 2026 at 9:57 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.