Check out Scrivo

Do you want to try out Scrivo? Then here's a demo for you that does not just get your feet wet but lets you plunge right in.

Contact us

For more information, please contact us. We're happy to help you out!

Next Sep 27 Previous

Item 547238

Your application needs to handle file uploads performed with HTTP PUT. How can you retrieve this data?

A. $_FILES superglobal B. C'mon PUT? What's next: PULL? Hey dude you're from Holland, right? Say no more, LOL. C. php://input stream D. php://stdin stream

Answer

No I'm not making up HTTP methods, PUT is valid HTTP method especially designed for sending files to a server over HTTP.

The files uploaded using the PUT method will not end up in the PHP $_FILE superglobal. That's only for files that were send using a POST request using a multipart/form-data encoded request body.

The PHP stream php://stdin hasn't much to do with HTTP and Web servers, use this stream to get input from the console when using PHP in command line mode. Take this program for example:

[/code]

And use it on the command line as:

php hello.php

[/code]

So the correct answer is C: you can retrieve the data uploaded with PUT by reading the php://input stream. Here's a little example to get you going.

The script that sends the request (put1.php):

 array(
                    "method" => "PUT",
                    "header" => "Content-type: text/plain",
                    "content" => "This is the payload"
                )
            )
        )
    )
);
?>

[/code]

The script that receives the request (put2.php):

[/code]