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

  • Home
  • SEARCH
  • 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 8515235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:05:35+00:00 2026-06-11T05:05:35+00:00

Is it possible to upload a file to an apache php server without including

  • 0

Is it possible to upload a file to an apache php server without including the content-length header ?

I am trying to stream a file that I am creating on the fly as a file upload. When I don’t use the content-length header I got the apache “501 Method Not Implemented”.

$sock = fsockopen($host,80,$errno, $error);
fwrite($sock, "POST $resource HTTP/1.1\r\n" .
                     "Host: $host\r\n\r\n");
fwrite($sock,fread($readHandle,filesize($file)));

If I include the content-length it works fine.

The server is reading from php://input

  • 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-06-11T05:05:37+00:00Added an answer on June 11, 2026 at 5:05 am

    According to the HTTP spec you aren’t technically required to specify the Content-Length header. From RFC 2616 14.13:

    Applications SHOULD use this field to indicate the transfer-length of
    the message-body, unless this is prohibited by the rules in section
    4.4.

    However, this is a pretty standard requirement for most servers, and they’ll generally send back an error response if the Content-Length header is missing or incorrectly specified. For all intents and purposes, SHOULD in this case equates to MUST.

    The problem is that (especially with keep-alive connections), the server doesn’t know when your request message actually ends without the Content-Length header. The other option if you’re streaming a request entity body is to send a Transfer-Encoding: chunked header and manually send one chunk of the entity body at a time.

    So in summary, if you want to send an entity body with your message but don’t want to send a Content-Length header, your only real option is to send a chunked HTTP message. This is basically required if you want to stream that entity body and don’t know its length ahead of time.

    How to chunk-encode an HTTP entity body for streaming …

    Transfer-Encoding: chunked means that you’re encoding the entity body of the HTTP message according to the constraints laid out in RFC2616 Sec3.6.1. This encoding format can be applied to either requests or responses (duh, they’re both HTTP messages). This format is extremely useful because it allows you to start sending an HTTP message right away before you know the size of the entity body or even exactly what that entity body is going to be. In fact, this is exactly what PHP does transparently for you when you echo any output without having sent a length header like header('Content-Length: 42').

    I’m not going to get into details of chunked encoding — that’s what the HTTP spec is for — but if you want to stream a request entity body you need to do something like this:

    <?php
    
    $sock = fsockopen($host,80,$errno, $error);
    $readStream = fopen('/some/file/path.txt', 'r+');
    
    fwrite($sock, "POST /somePath HTTP/1.1\r\n" .
                  "Host: www.somehost.com\r\n" .
                  "Transfer-Encoding: chunked\r\n\r\n");
    
    while (!feof($readStream)) {
        $chunkData = fread($readStream, $chunkSize);
        $chunkLength = strlen($chunkData);
        $chunkData = dechex($chunkLength) . "\r\n$chunkData\r\n";
    
        fwrite($sock, $chunkData);
    }
    
    fwrite($sock, "0\r\n\r\n");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is possible to upload a file on apache server using commons-fileuploader jar file in
Possible Duplicate: upload a file to server without using a form? I'am able to
Is it possible to upload a file to the FTP server using PHP script
Is it possible to upload a file to another server or pass a file
Possible Duplicate: how to upload a audio file from iphone documents folder to server
Is it possible to upload a file through html to javascript without having to
Is it possible to upload a user file and pass its content to a
is it possible to upload an entire plist file to a remote server or
Is it possible to upload a file into a subfolder on an FTP server?
is it possible to upload a file and subsequently when receiving response download the

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.