Problem using HTTP PUT Method.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
claws
Forum Commoner
Posts: 73
Joined: Tue Jun 19, 2007 10:54 am

Problem using HTTP PUT Method.

Post by claws »

Hey all,


I enabled HTTP PUT on my apache web server and I'm using this cgi script to handle HTTP PUT request

Code: Select all

 
<?php
 
//------ This is the cgi script I'm using handle PUT request 
 
 
/* PUT data comes in on the stdin stream */
$putdata = fopen("php://input", "r");
 
/* Open a file for writing */
$fp = fopen("myputfile.ext", "w");
 
/* Read the data 1 KB at a time
   and write to the file */
while ($data = fread($putdata, 1024))
  fwrite($fp, $data);
 
/* Close the streams */
fclose($fp);
fclose($putdata);
?>
 
This is the client program to make HTTP PUT request.

Code: Select all

 
    $host="localhost";
    $port = 80;
    // open a client connection
    $sock_stream = fsockopen ($host, $port, $errno, $errstr);
    if (!$sock_stream)
    {
        $result = "Error: could not open socket connection";
    }
    else
    {
         $message = "PUT /temp.file HTTP/1.1\r\nHost: localhost\r\n\r\nthis is the sample text";
        fputs ($sock_stream, $message);
        // get the result
        $result = fgets ($sock_stream, 1024);
        fclose ($sock_stream);
    }
    echo $result;
 
Server is returning "HTTP/1.1 200 OK" status line, but the data(HTTP PUT request msg body) is not there in the file created on the server. I mean "this is the sample text" should be written on to the file, but the file is empty.


pls help me in finding out whats going wrong.
claws
Forum Commoner
Posts: 73
Joined: Tue Jun 19, 2007 10:54 am

Re: Problem using HTTP PUT Method.

Post by claws »

Any suggestions please...
Post Reply