<?php
$header = <<<heredoc
POST /index.php HTTP/1.1\r\nUser-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5\r\nHost: nginx.selfimpr.org\r\nAccept: */*\r\nContent-Length: %d\r\nContent-Type: multipart/form-data; boundary=----------------------------4db878605894; charset=utf-8\r\n\r\n
heredoc;
/* notice here */
/* if I change the header Content-Type to "Content-Type: multipart/form-data; boundary=----------------------------4db878605894\r\n", it will work fine */
$body = <<<heredoc
------------------------------4db878605894\r\nContent-Disposition: form-data; name="image"; filename="big.jpg"\r\nContent-Type: image/jpeg\r\n\r\n
heredoc;
$body .= file_get_contents('/Users/selfimpr/big.jpg');
$body .= "\r\n-----------------------------4db878605894--\r\n";
$header = sprintf($header, strlen($body));
$fp = fsockopen('nginx.selfimpr.org', 80);
fwrite($fp, $header . $body);
echo fread($fp, 4096);