HTTP PUT for file uploads

mike mike503 at
Sat Aug 2 22:43:45 MSD 2008

On 8/2/08, Michael <nginx at> wrote:

> Do you mean to have 'rw' there?

Nope :)

Got it to work:

nginx access log: - - [02/Aug/2008:11:39:53 -0700] PUT /put/work.php
HTTP/1.1 "200" 5 "-" "-" "-"

PHP curl script to test (ran from shell):

$file = 'china.txt';
$length = filesize($file);
$ch = curl_init();
$url = "";
$fh = fopen($file, 'r');
curl_setopt($ch, CURLOPT_INFILE, $fh);
curl_setopt($ch, CURLOPT_INFILESIZE, $length);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

i believe you can use a @ or something for the input to a curl script
(instead of opening a filehandle) and it will consider that a file on
the filesystem, but i was just looking for a quick test script. it
will actually be an in-browser applet uploading this, i just wanted to
pick apart the receiving end and test it can be done.

PHP work.php script to receive (VERY crappy code, just trying
different things out):

$fname = '/tmp/uploadtest.txt';
$data = '';
$putdata = fopen('php://input', 'r');
while(!feof($putdata)) {
    $data .= fread($putdata,1024);
file_put_contents($fname, $data);


More information about the nginx mailing list