From: r-ser at yandex dot ru Operating system: Linux 2.6.26 PHP version: 5.2.9 PHP Bug Type: HTTP related Bug description: file_get_contents "Content-Length" problem
Description: ------------ When use file_get_contents + stream_context_create to post file to web server and the page in web server return redirect to another page ("location" field in answer), then file_get_contents requested redirected page with POST header without "Content-Length:" field in request and server response "HTTP/1.0 411 Length Required". I think, it's two ways to fix problem 1) 'method' must be change to GET in requests to redirect pages. 2) Add 'Content-Length: 0' to next POST redirect requests Reproduce code: --------------- $argv[1] = "image.jpg"; $boundary = "AaB03x1234567890"; $type = mime_content_type($argv[1]); $data = "--$boundary\r\nContent-Disposition: form-data; name=\"fileupload\"; filename=\"".basename($argv[1])."\" Content-Type: ".$type." \r\nContent-Transfer-Encoding: binary\r\n\r\n".file_get_contents($argv[1])."\r\n--$boundary--"; $header = "Content-type: multipart/form-data, boundary=$boundary"; $context = stream_context_create(array('http' => array('method'=>'POST', 'header'=> $header, 'content' => $data))); $result = file_get_contents('http://load.imageshack.us', false, $context); echo $result; Expected result: ---------------- failed to open stream: HTTP request failed! HTTP/1.0 411 Length Required Actual result: -------------- Normal redirected page -- Edit bug report at http://bugs.php.net/?id=47684&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47684&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47684&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47684&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=47684&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47684&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=47684&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=47684&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=47684&r=needscript Try newer version: http://bugs.php.net/fix.php?id=47684&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=47684&r=support Expected behavior: http://bugs.php.net/fix.php?id=47684&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=47684&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=47684&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=47684&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47684&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=47684&r=dst IIS Stability: http://bugs.php.net/fix.php?id=47684&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=47684&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=47684&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=47684&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=47684&r=mysqlcfg